2012-03-04 164 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