C#:如何更改图像方向属性? [英] C#: How to change an image orientation property?

查看:381
本文介绍了C#:如何更改图像方向属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

foreach (var prop in img.PropertyItems)
{
      if (prop.Id == 0x0112) //value of EXIF
      {
         var orientation = img.GetPropertyItem(prop.Id).Value[0];
         switch (orientation)
         {
            case 1:
            // No rotation required.
            break;
            case 2:
            img.RotateFlip(RotateFlipType.RotateNoneFlipX);
            break;
            case 3:
            img.RotateFlip(RotateFlipType.Rotate180FlipNone);





我使用上面的代码来检测图像是否从原始状态改变。假设我将方向值设置为3并且我想将其设置为1的正常,那么我如何将该方向属性值3替换为1?



I have used above code to detect whether image orietation is changed from original. Suppose I have get orientation value as "3" and I want to set it to normal that is "1", so how I could replace that orientation property value 3 by 1?

推荐答案

尝试使用 Image.SetPropertyItem Method [ ^ ]像这样:



Try it with Image.SetPropertyItem Method [^] like this:

foreach (var prop in img.PropertyItems)
{
      if (prop.Id == 0x0112) //value of EXIF
      {
         var orientation = prop.Value;
         if (orientation == 3)
         {
             prop.Value[0] = 1;
             img.SetPropertyItem(prop);
         }
     }
}


这篇关于C#:如何更改图像方向属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆