使用以下代码获取图像方向时出现问题
string fileName = @"D:\...\...\01012015004435.jpeg";
int rotate = 0;
using (var image = System.Drawing.Image.FromFile(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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在获得正确的方向后,我习惯像旋转图像一样
private static RotateFlipType OrientationToFlipType(string orientation)
{
switch (int.Parse(orientation))
{
case 1:
return RotateFlipType.RotateNoneFlipNone;
break;
case 2:
return RotateFlipType.RotateNoneFlipX;
break;
case 3:
return RotateFlipType.Rotate180FlipNone;
break;
case 4: …
Run Code Online (Sandbox Code Playgroud) c# ×1