拍摄的照片才有EXIF信息 ,可能支持:[.jpg] 、[.jpeg] 、[.gif]、[.png]、[.bmp]自己试 | Add-Type -AssemblyName System.Drawing | | function Get-ExifData { | | param([string]$ImagePath) | | try { | | $bitmap = [System.Drawing.Bitmap]::FromFile($ImagePath) | | $exifData = [ordered]@{} | | | | | | $exifTagMap = @{ | | 0x010F = "生产厂商" | | 0x0110 = "设备型号" | | 0x0131 = "固件版本" | | 0x0213 = "色相配置" | | 0x0112 = "图像方向" | | 0x0132 = "最后修改时间" | | 0x8769 = "EXIF信息块" | | 0x829A = "曝光时间" | | 0x829D = "光圈系数" | | 0x8827 = "感光度" | | 0x9003 = "拍摄时间" | | 0x9004 = "数字化时间" | | | | 0x9201 = "快门速度值" | | 0x9202 = "光圈值" | | 0x9204 = "曝光补偿" | | 0x9207 = "测光模式" | | 0x9208 = "白平衡" | | 0x9209 = "闪光灯状态" | | 0x920A = "物理焦距" | | 0x9290 = "原始日期时间数字化(秒)" | | 0x9291 = "原始日期时间(秒)" | | 0x9292 = "日期时间(秒)" | | 0xA002 = "像素宽度" | | 0xA003 = "像素高度" | | 0x8889= "未定义" | | 0x0000 = "GPS版本信息" | | 0x0001 = "纬度参考(N/S)" | | 0x0002 = "GPSLatitude" | | 0x0003 = "经度参考(E/W)" | | 0x0004 = "GPSLongitude" | | 0x0005 = "海拔参考" | | 0x0006 = "海拔值" | | 0x011A = "水平分辨率" | | 0x011B = "垂直分辨率" | | 0x0128 = "分辨率单位" | | 0x8822 = "曝光模式" | | 0x9000 = "处理模式" | | 0x9101 = "像素排列" | | 0xA000 = "FlashPix版本" | | | | 0x5041 = "互操作标识" | | 0x9205 = "最大光圈" | | 0x927C = "厂商注释" | | 0xA404 = "数字变焦" | | 0xA401 = "传感器类型" | | 0x001D = "拍摄时间" | | | | | | 0x0011 = "GPS处理方式" | | 0x9C9B = "小米扩展信息" | | 0xA001 = "色彩空间" | | 0xA217 = "拍摄场景" | | 0x9400 = "环境温度(℃)" | | 0x9401 = "环境湿度(%)" | | } | | foreach ($prop in $bitmap.PropertyItems) { | | $propName = if ($exifTagMap.ContainsKey($prop.Id)) { | | $exifTagMap[$prop.Id] | | } else { | | "Unknown_0x{0:X4}" -f $prop.Id | | } | | | | try { | | $value = switch ($prop.Type) { | | 2 { | | [System.Text.Encoding]::ASCII.GetString($prop.Value).TrimEnd("`0") | | } | | 3 { | | [System.BitConverter]::ToUInt16($prop.Value, 0) | | } | | 4 { | | [System.BitConverter]::ToUInt32($prop.Value, 0) | | } | | 5 { | | $num = [System.BitConverter]::ToUInt32($prop.Value, 0) | | $den = [System.BitConverter]::ToUInt32($prop.Value, 4) | | if ($den -ne 0) { $num / $den } else { 0 } | | } | | 7 { | | [System.BitConverter]::ToString($prop.Value) | | } | | default { | | [System.BitConverter]::ToString($prop.Value) | | } | | } | | | | | | | | | | if ($propName -match "GPS(Latitude|Longitude)") { | | $degrees = [BitConverter]::ToUInt32($prop.Value, 0) / 1 | | $minutes = [BitConverter]::ToUInt32($prop.Value, 4) / 1 | | $seconds = [BitConverter]::ToUInt32($prop.Value, 8) / 10000 | | $value = "{0}°{1}'{2:F4}""{3}" -f $degrees, $minutes, $seconds, $prop.Value[12] | | | | } | | $exifData[$propName] = $value | | } catch { | | $exifData[$propName] = "Error: $_" | | } | | } | | | | | | $exifData.GetEnumerator() | Format-Table @{ | | Label = "属性名称" | | Expression = { $_.Key } | | }, @{ | | Label = "属性值" | | Expression = { $_.Value } | | }, @{ | | Label = "描述" | | Expression = { | | switch ($_.Key) { | | 'Model' { '型号' } | | 'Software' { '软件' } | | 'DateTime' { '日期和时间' } | | 'FNumber' { '光圈值' } | | 'ExposureTime' { '曝光时间(秒)' } | | 'ISOSpeedRatings'{ '感光度' } | | 'FocalLength' { '焦距(毫米)' } | | 'GPSLatitude' { '纬度(度,分,秒)' } | | 'GPSLongitude' { '经度(度,分,秒)' } | | default { '无描述信息' } | | } | | } | | } | | | | } catch { | | Write-Error "处理文件时出错:$($_.Exception.Message)" | | } finally { | | if ($bitmap) { $bitmap.Dispose() } | | } | | } | | | | | | Get-ExifData -ImagePath "$env:USERPROFILE\Desktop\IMG_20250327_163811.jpg" | | pauseCOPY |
|