在为来自最近相机的照片编写关键字时,InPlaceBitmapMetadataWriter失败

时间:2018-10-29 18:10:21

标签: c# metadata jpeg imaging xmp

我已经成功地使用InPlaceBitmapMetadataWriter为许多相机拍摄的许多照片编写了关键字,包括当我需要扩展metdata填充时。但是,对于由最近的相机拍摄的照片,TrySave方法对于“关键字”始终返回false。有谁知道这可能是为什么以及我该如何解决?

        using (Stream jpgFileStream = File.Open(tempPath, FileMode.Open, FileAccess.ReadWrite))
        {
            // BitmapCacheOption.None tells the decoder to delay decoding until encoding. The JPEG 
            // encoder understands that the input was a JPEG and just copies over the image bits without decompressing 
            // and recompressing them to perform a lossless operation.
            BitmapDecoder jpgDecoder = BitmapDecoder.Create(jpgFileStream, BitmapCreateOptions.None, BitmapCacheOption.None);

            if (jpgDecoder.Frames[0] != null && jpgDecoder.Frames[0].Metadata != null)
            {
                InPlaceBitmapMetadataWriter metadataJpgWriter = jpgDecoder.Frames[0].CreateInPlaceBitmapMetadataWriter();

                metadataJpgWriter.SetQuery("System.Keywords", Keywords.ToArray());;

                if (metadataJpgWriter.TrySave())
                {
                    traySaveSuccessful = true;
                }
            }
        }

0 个答案:

没有答案