[英]System.Drawing Bitmap gives wrong dimensions
万一其他社区成员需要它,您只需访问图像属性并检查id元素274上的值即可。如果您想了解更多有关此问题的信息,请参阅《 阅读JPEG元数据(方向)》 ,该指南对当我解决这个问题时,我很忙。
这可能无法很好地解决宽度/高度问题,但至少可以确定图片的方向。
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.