0

我正在处理这段代码:内部方法调用元数据属性都已填充;但在用户代码中,它们中的大多数都为空。为什么会有这种行为?

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
4

1 回答 1

0

当超出使用范围时,BitmapDecoder 将被释放。在线检查调试器中的元数据,return meta您将看到。

于 2011-10-26T08:06:28.820 回答