And*_*ndi 11
您可以从文件扩展属性中获取大部分此类信息,如下所示:
$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)
Run Code Online (Sandbox Code Playgroud)
你也可以通过其他方式获得尺寸(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
Run Code Online (Sandbox Code Playgroud)
更新2 PixelFormat属性为您提供位深度.
$png.PixelFormat
Run Code Online (Sandbox Code Playgroud)
该属性是可能格式的枚举.您可以在此处查看完整列表:
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx
例如Format32bppArgb,定义为
指定格式为每像素32位; 每个8位用于alpha,红色,绿色和蓝色分量.
您可能想使用包含 get-image 的PowershellPack 模块:
PS D:\> import-module psimagetools
PS D:\> get-item .\fig410.png | get-image
FullName : D:\fig410.png
FormatID : {B96B3CAF-0728-11D3-9D7B-0000F81EF32E}
FileExtension : png
FileData : System.__ComObject
ARGBData : System.__ComObject
Height : 450
Width : 700
HorizontalResolution : 96,0119934082031
VerticalResolution : 96,0119934082031
PixelDepth : 32
IsIndexedPixelFormat : False
IsAlphaPixelFormat : True
IsExtendedPixelFormat : False
IsAnimated : False
FrameCount : 1
ActiveFrame : 1
Properties : System.__ComObject
Run Code Online (Sandbox Code Playgroud)或者您可以直接使用Wia.ImageFile(这就是 get-image 函数的做法):
PS D:\> $image = New-Object -ComObject Wia.ImageFile
PS D:\> $image.loadfile("D:\fig410.png")
PS D:\> $image
FormatID : {B96B3CAF-0728-11D3-9D7B-0000F81EF32E}
FileExtension : png
FileData : System.__ComObject
ARGBData : System.__ComObject
Height : 450
Width : 700
HorizontalResolution : 96,0119934082031
VerticalResolution : 96,0119934082031
PixelDepth : 32
IsIndexedPixelFormat : False
IsAlphaPixelFormat : True
IsExtendedPixelFormat : False
IsAnimated : False
FrameCount : 1
ActiveFrame : 1
Properties : System.__ComObject
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
10733 次 |
| 最近记录: |