BitmapMetadata: очистка некоторых свойств?

Я имею дело с этим кодом: внутри вызова метода все свойства метаданных заполнены; но в коде пользователя большинство из них обнуляется. Почему это поведение?

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

1 ответ

При выходе из области применения BitmapDecoder будет удален. Проверьте мета в отладчике на линии return meta и ты увидишь.

Другие вопросы по тегам