Pho*_*der 3 vb.net image picturebox image-rotation
我的项目有一个用于加载图片的图片框控件,它工作正常。
但是,一些垂直 jpg 图片在 Windows 资源管理器和我的图片框控件中水平显示 - 使用 Photoshop 等编辑器打开的同一文件显示垂直方向。
如何让图片以正确的方向显示在图片框控件中?
您需要检查图像并从 exif 标签中提取方向信息。
您需要做的第一件事是获得一个 exif 阅读器。例如,在Code Project上有一个用 VB.NET 编写的。
如果您将文件加载到一个中,Image您将能够从PropertyItems(如此 C# 代码所示)读取 EXIF 属性:
using (Image image = Image.FromFile(imageName))
{
// Non property item properties
this.FileName = imageName;
PixelFormat = image.PixelFormat;
this.Width = image.Size.Width;
this.Height = image.Size.Height;
foreach (PropertyItem pi in image.PropertyItems)
{
EXIFPropertyItem exifpi = new EXIFPropertyItem(pi);
this.propertyItems.Add(exifpi);
}
}
Run Code Online (Sandbox Code Playgroud)
哪里EXIFPropertyItem是转换一个类PropertyItem。所述PropertyItem的Id是EXIF代码(取向感0x0112)。
然后查找 Orientation 属性并读取它的值。值 5、6、7 和 8 用于纵向(垂直)图像,例如,6 表示旋转 90 度,8 表示旋转 -90 度。
获得方向后,您可以调用适当的旋转变换以正确的方向显示图像。