【问题标题】:Reset Image Orientation EXIF metadata flag重置图像方向 EXIF 元数据标志
【发布时间】:2014-07-25 15:18:24
【问题描述】:

我正在将一张图片导入我的应用程序并根据 EXIF 元数据旋转图片。在此之后,我将旋转后的图像保存到我的磁盘上,但由于我仍然在图像上留下了旋转后的图像元数据,并且 windows 认为它​​应该再次旋转它......基本上意味着我的图像最终是颠倒的。

到目前为止,我得到了:

            using (Stream sourceStream = File.Open(dlg.FileName, FileMode.Open, FileAccess.Read))
            {
                BitmapDecoder sourceDecoder = BitmapDecoder.Create(sourceStream, createOptions, BitmapCacheOption.OnLoad);
                // Check source is has valid frames 
                if (sourceDecoder.Frames[0] != null && sourceDecoder.Frames[0].Metadata != null)
                {
                    sourceDecoder.Frames[0].Metadata.Freeze();
                    // Get a clone copy of the metadata
                    BitmapMetadata sourceMetadata = sourceDecoder.Frames[0].Metadata.Clone() as BitmapMetadata;
                    ImportedPhotoMetaData = sourceMetadata;
                }
            }

和

                using (var image = Image.FromFile(dlg.FileName))
                {
                    foreach (var prop in image.PropertyItems)
                    {
                        if (prop.Id == 0x112)
                        {
                            if (prop.Value[0] == 6)
                                rotate = 90;
                            if (prop.Value[0] == 8)
                                rotate = -90;
                            if (prop.Value[0] == 3)
                                rotate = 180;
                            prop.Value[0] = 1;
                        }
                    }
                }

但是 prop.Value[0] = 1;行似乎没有重置图像元数据。我需要在 ImportedPhotoMetaData 属性上重置图像方向

【问题讨论】:

标签: c# image orientation metadata


【解决方案1】:

知道了... 替换

prop.Value[0] = 1;

与

ImportedPhotoMetaData.SetQuery("System.Photo.Orientation", 1);

【讨论】:

  • 我正在尝试使用您的答案来帮助我解决问题,但我很难找到相关文档。如果您更新您的答案以包含指向文档的链接,以及更多说明,我会给您一个赞成票。
  • 对于未来的读者:ImportedPhotoMetaData 显然存在于 System.Photo namespace 中,并且可能不适用于您的目标平台或框架版本 - 例如我不能将它用于 .NET4.0。我找到了this SO question that has a good answer that is working for me
猜你喜欢
  • 1970-01-01
  • 2012-12-25
  • 1970-01-01
  • 2013-07-11
  • 2017-09-11
  • 2018-12-26
  • 1970-01-01
  • 2014-11-05
  • 1970-01-01
相关资源
最近更新 更多