2012-03-04 60 views

回答

7

你可以得到大多数从扩展属性类似这样的文件,这样的信息:

$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被定义为

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

+0

感谢您的回答。我最终选择使用Wia.ImageFile。我可以更简单地获得一些信息(比如深度)。 – Etienne 2012-03-04 18:45:28

+0

@Etienne我添加了另一个选项。你可以使用.NET并避免使用COM。 – 2012-03-04 19:01:51

+0

感谢您的最新更新。我是PowerShell的初学者,所以如果我明白最好使用.NET而不是COM?随着Wia.ImageFile我还发现IsIndexedPixelFormat,IsAlphaPixelFormat,IsExtendedPixelFormat和IsAnimated,这是我的需要感兴趣。我还没有设法通过System.Drawing找到它们。非常感谢您的回答,非常感谢。艾蒂安。 – Etienne 2012-03-05 03:34:02

2
  • 您可能需要使用包含获取图像的PowershellPack Module的文章:

    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 
    
  • 或者你可以直接使用Wia.ImageFile(这是获取图像功能是如何实现的):

    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 
    
+0

未找到链接,任何替代品? – Kiquenet 2016-08-05 05:51:50

+0

没有官方链接,但https://github.com/thlorenz/settings/tree/master/WindowsPowerShell/Modules可能有帮助 – 2016-08-05 14:31:12