如何從PowerShell中的特定.png文件獲取詳細信息?
像尺寸,位深和尺寸。從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
被定義爲
指定格式爲每像素32位;對於alpha,紅色,綠色和藍色分量,每個8位都使用 。
腳本專家寫的越來越基於文件的元數據上Shell.Application http://blogs.technet.com/b/heyscriptingguy/archive/2008/08/13/how-can-i-find-files-metadata.aspx
您可能需要使用包含獲取圖像的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
未找到鏈接,任何替代品? – Kiquenet 2016-08-05 05:51:50
沒有官方鏈接,但https://github.com/thlorenz/settings/tree/master/WindowsPowerShell/Modules可能有幫助 – 2016-08-05 14:31:12
- 1. 從照片中獲取詳細信息
- 2. 獲取Facebook詳細信息
- 3. 獲取擴展文件信息的詳細信息
- 4. 從ActivatedRouteSnapshot獲取路線詳細信息
- 5. 從log.nsf獲取用戶詳細信息
- 6. 從MGTwitterEngine獲取用戶詳細信息
- 7. 從貝寶獲取詳細信息?
- 8. C#從子類獲取詳細信息
- 9. 從plist文件中獲取詳細信息與objective-c
- 10. 從.MSG附件中獲取郵件項目詳細信息
- 11. Android主詳細信息詳細信息
- 12. Crystal Reports詳細信息詳細信息
- 13. 如何在Java中獲取文件的「詳細信息」
- 14. 獲取額外的PaperSource詳細信息
- 15. C#獲取過程的詳細信息
- 16. 獲取短信的詳細信息從它的ID Android
- 17. 獲取DataGrid行詳細信息
- 18. Databasemetadata獲取列詳細信息
- 19. SPNEGO獲取用戶詳細信息
- 20. 如何獲取異常詳細信息
- 21. LINQ:獲取表詳細信息
- 22. Foursquare獲取場地詳細信息
- 23. 獲取最後登錄詳細信息
- 24. ActiveDirectoryLdapAuthenticationProvider:獲取用戶詳細信息
- 25. 獲取API詳細信息到console.log
- 26. Get-ADGroupMember獲取用戶詳細信息?
- 27. 獲得詳細的零件信息
- 28. c#獲取windows用戶配置文件的詳細信息?
- 29. git命令獲取特定文件的提交詳細信息
- 30. 獲取與文件關聯的TFS服務器詳細信息
感謝您的回答。我最終選擇使用Wia.ImageFile。我可以更簡單地獲得一些信息(比如深度)。 – Etienne 2012-03-04 18:45:28
@Etienne我添加了另一個選項。你可以使用.NET並避免使用COM。 – 2012-03-04 19:01:51
感謝您的最新更新。我是PowerShell的初學者,所以如果我明白最好使用.NET而不是COM?隨着Wia.ImageFile我還發現IsIndexedPixelFormat,IsAlphaPixelFormat,IsExtendedPixelFormat和IsAnimated,這是我的需要感興趣。我還沒有設法通過System.Drawing找到它們。非常感謝您的回答,非常感謝。艾蒂安。 – Etienne 2012-03-05 03:34:02