我正在处理这段代码:在内部方法调用中,元数据属性都被填充; 但在用户代码中,大多数都是无效的。为什么会出现这种情况?
public static BitmapFrame GetImageIPTC(string imageFile)
{
BitmapFrame meta;
using (var fs = new FileStream(imageFile, FileMode.Open))
{
BitmapDecoder decoder = new JpegBitmapDecoder(fs, BitmapCreateOptions.None, BitmapCacheOption.None);
meta = decoder.Frames[0];
var a = ((BitmapMetadata) meta.Metadata).CameraModel;
}
return meta;
}
在方法内部,元数据属性为:
ApplicationName "Adobe Photoshop CS5 Windows" string
- Author Count = 1 System.Collections.ObjectModel.ReadOnlyCollection<string>
[0] "Michele Virgilio" string
CameraManufacturer "Canon" string
CameraModel "Canon EOS 450D" string
Comment null string
Copyright "© Michele Virgilio" string
DateTaken "16/04/2011 10:30:48" string
Format "jpg" string
IsFixedSize false bool
IsReadOnly false bool
+ Keywords Count = 96 System.Collections.ObjectModel.ReadOnlyCollection<string>
Location "/" string
Rating 0 int
Subject "Subject description" string
Title "Title description" string
用户代码:
var actual = ImageInfo.GetImageIPTC(filespec);
var bitmapMetadata = (BitmapMetadata)actual.Metadata;
var a = bitmapMetadata.CameraModel;
正如你所看到的那样,除了主题:
之外的所有属性 ApplicationName "Adobe Photoshop CS5 Windows" string
- Author Count = 1 System.Collections.ObjectModel.ReadOnlyCollection<string>
[0] "Michele Virgilio" string
CameraManufacturer "Canon" string
CameraModel "Canon EOS 450D" string
Comment null string
Copyright "© Michele Virgilio" string
DateTaken "16/04/2011 10:30:48" string
Format "jpg" string
IsFixedSize false bool
IsReadOnly true bool
+ Keywords Count = 96 System.Collections.ObjectModel.ReadOnlyCollection<string>
Location "/" string
Rating 0 int
Subject null string
Title "Title description" string
答案 0 :(得分:0)
当离开使用范围时,将处理BitmapDecoder。检查return meta
行调试器中的元数据,您将看到。