Bitmap 图片旋转

#region 图片旋转
public static void rotating(Bitmap img, ref int width, ref int height)
{
int ow = width;
int orien = 1;
foreach (var prop in img.PropertyItems)
{
if (prop.Id == 0x112)
{
orien = prop.Value[0];
}
}
switch (orien)
{
case 2:
img.RotateFlip(RotateFlipType.RotateNoneFlipX);//horizontal flip
break;
case 3:
img.RotateFlip(RotateFlipType.Rotate180FlipNone);//right-top
break;
case 4:
img.RotateFlip(RotateFlipType.RotateNoneFlipY);//vertical flip
break;
case 5:
img.RotateFlip(RotateFlipType.Rotate90FlipX);
break;
case 6:
img.RotateFlip(RotateFlipType.Rotate90FlipNone);//right-top
width = height;
height = ow;
break;
case 7:
img.RotateFlip(RotateFlipType.Rotate270FlipX);
break;
case 8:
img.RotateFlip(RotateFlipType.Rotate270FlipNone);//left-bottom
width = height;
height = ow;
break;
default:
break;
}
}
#endregion

原文地址:https://www.cnblogs.com/xiaohong520789/p/11201670.html