【问题标题】:System.Drawing Bitmap gives wrong dimensionsSystem.Drawing Bitmap 给出了错误的尺寸
【发布时间】:2019-10-19 04:08:27
【问题描述】:

这在某些情况下会导致内存不足异常,谁能告诉我为什么会发生这种情况以及最简单的解决方法是什么?

【问题讨论】:

  • 最简单的修复方法似乎是限制纵向类型的图像并强制横向
  • 很可能某处有某种形式的轮换标志没有被兑现
  • 也许这篇文章对你有帮助:stackoverflow.com/questions/6222053/…
  • 在 gimp 中打开图像抱怨 EXIF 数据,因此最有可能的解决方案将在该帖子中。感谢指导

标签: c# system.drawing


【解决方案1】:

以防万一其他社区成员需要它,您只需访问图像属性并检查 id 元素 274 上的值。如果您想了解有关此问题的更多信息,请参阅 Problem reading JPEG Metadata (Orientation) 这对我有帮助我在解决这个问题时花了很多时间。

这可能不能很好的解决宽高问题,但至少图片的方向是可以的。

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);
    }
}

【讨论】:

  • 标记为答案,因为它链接到我使用的帖子(也在 cmets 中)并且它解决了我的问题。
猜你喜欢
  • 2016-08-03
  • 1970-01-01
  • 2021-07-26
  • 1970-01-01
  • 1970-01-01
  • 2018-03-06
  • 2015-10-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多