简体   繁体   English

System.Drawing位图给出错误的尺寸

[英]System.Drawing Bitmap gives wrong dimensions

在此处输入图片说明

This would result in out of memory exception in some cases, can anyone tell me why is it happening and what would be the easiest workaround? 在某些情况下,这将导致内存不足异常,有人可以告诉我为什么会发生这种情况,最简单的解决方法是什么?

Just in case any other community member needs it, you can just simply access to image properties and check for the value on the id element 274. If you want to know quite more about this issue refer to Problem reading JPEG Metadata (Orientation) which helped me a lot while I was solving this. 万一其他社区成员需要它,您只需访问图像属性并检查id元素274上的值即可。如果您想了解更多有关此问题的信息,请参阅《 阅读JPEG元数据(方向)》 ,该指南对当我解决这个问题时,我很忙。

This may not solve the width/height issue in a very good way, but at least the orientation of the picture will be ok. 这可能无法很好地解决宽度/高度问题,但至少可以确定图片的方向。

using(var image = new Bitmap(filePath))
{
    PropertyItem propertie = image.PropertyItems.FirstOrDefault(p => p.Id == 274);
    if (propertie != null)
    {
        int orientation = propertie.Value[0];
        if (orientation == 6)
            image.RotateFlip(RotateFlipType.Rotate90FlipNone);
        if (orientation == 8)
            image.RotateFlip(RotateFlipType.Rotate270FlipNone);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM