我有一个脚本循环遍历我拍摄的大量图像并读取焦距和相机模型,显示焦距和总数的图形(这对于帮助确定下一个镜头购买非常有用,但除此之外要点).
这对于10 MB以下的JPG图像来说绝对可以正常工作,但只要它接近20 MB的RAW文件(如Canon的CR2格式),它就会吐出"Out of Memory"错误.
有没有办法在Powershell中增加内存限制,或者只是在不加载整个文件的情况下读取文件的元数据..?
这就是我目前使用的:
# load image by statically calling a method from .NET
$image = [System.Drawing.Imaging.Metafile]::FromFile($file.FullName)
# try to get the ExIf data (silently fail if the data can't be found)
# http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html
try
{
# get the Focal Length from the Metadata code 37386
$focalLength = $image.GetPropertyItem(37386).Value[0]
# get model data from the Metadata code 272
$modelByte = $image.GetPropertyItem(272)
# convert the model data to a String from a Byte Array
$imageModel = $Encode.GetString($modelByte.Value) …Run Code Online (Sandbox Code Playgroud)