如何从 PowerShell 中的特定 .png 文件获取详细信息?
像尺寸,位深度和大小。
最佳答案
您可以从文件扩展属性中获取大部分信息,如下所示:
$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
.位深度属性似乎没有列在扩展属性中,尽管它在您右键单击文件时可用。
更新 另一种选择是正确使用 .NET 以避免使用 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 属性为您提供位深度。
$png.PixelFormat
该属性是可能格式的枚举。您可以在此处查看完整列表:
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx
例如
Format32bppArgb
被定义为Specifies that the format is 32 bits per pixel; 8 bits each are used for the alpha, red, green, and blue components.
关于powershell - 在 PowerShell 中从 .png 文件中获取详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9552367/