相关疑难解决方法(0)

获取图像方向并按方向旋转

使用以下代码获取图像方向时出现问题

    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#

22
推荐指数
3
解决办法
2万
查看次数

标签 统计

c# ×1