2016-10-26 49 views
0

当我查看数码相机拍摄的照片时,如果通过将相机转动90度拍摄照片,高度为4000,宽度为6016。高度是6016,宽度是4000.一切都很好,如果我用文件资源管理器(Windows 10)检查图像的属性,它看起来对任何一张图都是正确的。如果我在Photoshop或图片查看器中查看图片,则所有的图片看起来都是正确的。在我的应用我使用EXIF得到的宽度和高度总是显示宽度6016和高度4000,如果我通过代码获取图像:在visual studio中反转的图像宽度和高度vb.net

dim orgimage as bitmap = new bitmap("C:/image/picture.jpg") 

宽度始终是6016,高度为4000始终,如果我通过Photoshop将4000更改为3999,则图像宽度和高度在我的应用程序中是正确的。这是Visual Studios Visual Basic的限制吗?

回答

1

不同之处在于其他应用程序正在手动应用Exif.Image.Orientation(标记274)的更正。

只需检查此标记并相应地旋转位图。

Public Function OrientateImage(img As Image) As Boolean 
    Const EXIF_ORIENTATION = 274 
    Dim orientationTag = img.PropertyItems.FirstOrDefault(Function(x) x.Id = EXIF_ORIENTATION) 
    If orientationTag IsNot Nothing Then 
     Dim orientation As Short = BitConverter.ToInt16(orientationTag.Value, 0) 
     Select Case orientation 
      Case 3 
       img.RotateFlip(RotateFlipType.Rotate180FlipNone) 
      Case 6 
       img.RotateFlip(RotateFlipType.Rotate90FlipNone) 
      Case 8 
       img.RotateFlip(RotateFlipType.Rotate270FlipNone) 
      Case Else 
       Return False 
     End Select 
    End If 
    Return True 
End Function 
+0

尼斯功能,不检查方向是我的问题,功能运行完美。 –

+0

没问题。如果这解决了你的问题,那么请打勾接受答案。 – FloatingKiwi

0

如果您检查方向属性,它可能有助于回答/帮助您在宽度和高度相同时从Camera输出中读取照片时出现问题。 请让我们知道您的发现。

Dim orgimage As bitmap = New Bitmap("C:/image/picture.jpg", True) 
Dim otherImage As bitmap = New Bitmap("C:/image/picture2.jpg", True) 
'Orientation 
Dim exifprop As Integer = orgimage.GetPropertyItem(274).Value(0) 
Dim exifprop2 As Integer = otherImage.GetPropertyItem(274).Value(0) 


'1 = Horizontal (normal) 
'2 = Mirror horizontal 
'3 = Rotate 180 
'4 = Mirror vertical 
'5 = Mirror horizontal and rotate 270 CW 
'6 = Rotate 90 CW 
'7 = Mirror horizontal and rotate 90 CW 
'8 = Rotate 270 CW 

EXIF tagsPropertyItem.Id 274