在PowerShell中从.png文件获取详细信息 [英] Get the detail informations from a .png file in PowerShell

查看:445
本文介绍了在PowerShell中从.png文件获取详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从PowerShell中的特定.png文件获取详细信息?
像尺寸,位深和大小一样.

How can I get the detail informations from a specific .png file in PowerShell?
Like dimensions, bit depth and size.

推荐答案

您可以从文件扩展属性中获取大部分信息,如下所示:

You can get most of this information from the files extended properties like this:

$path = 'D:\image.png'
$shell = New-Object -COMObject Shell.Application
$folder = Split-Path $path
$file = Split-Path $path -Leaf
$shellfolder = $shell.Namespace($folder)
$shellfile = $shellfolder.ParseName($file)

$width = 27
$height = 28
$Dimensions = 26
$size = 1

$shellfolder.GetDetailsOf($shellfile, $width)
$shellfolder.GetDetailsOf($shellfile, $height)
$shellfolder.GetDetailsOf($shellfile, $Dimensions)
$shellfolder.GetDetailsOf($shellfile, $size)

您还可以通过其他方式(例如(Get-Item D:\image.png).Length / 1KB)获得尺寸.

You can also get the size in other ways such as (Get-Item D:\image.png).Length / 1KB.

尽管扩展属性中没有显示位深度属性,即使右键单击该文件时该属性仍然可用.

The bit depth property doesn't seem to be listed in the extended properties though even though its available when you right click the file.

更新另一个选择是使用.NET以避免使用COM:

Update Another option is to use .NET proper to avoid using COM:

add-type -AssemblyName System.Drawing
$png = New-Object System.Drawing.Bitmap 'D:\image.png'
$png.Height
$png.Width
$png.PhysicalDimension
$png.HorizontalResolution
$png.VerticalResolution

更新2 PixelFormat属性为您提供位深度.

Update 2 The PixelFormat property gives you the bit depth.

$png.PixelFormat

该属性是可能格式的枚举.您可以在此处查看完整列表:

The property is an enumeration of possible formats. You can view the complete list here:

http://msdn.microsoft.com/zh-cn/library/system.drawing.imaging.pixelformat.aspx

例如Format32bppArgb被定义为

指定格式为每个像素32位;每个使用8位 用于alpha,红色,绿色和蓝色分量.

Specifies that the format is 32 bits per pixel; 8 bits each are used for the alpha, red, green, and blue components.

这篇关于在PowerShell中从.png文件获取详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆