skip to Main Content

When I view a photograph taken with a digital camera the height is 4000 and the width is 6016, if I take the picture by turning the camera 90 Deg. the height is 6016 and the width is 4000. All is good, if I examine the properties of the image with file explorer(Windows 10) it looks correct for either picture. If I view the picture in Photoshop or picture viewer all looks correct as far as orientation. In my app I use exif to get the width and height it always shows width as 6016 and height as 4000. if I get an image via code:

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

the width is always 6016 and the height is always 4000, if I change the 4000 to 3999 via Photoshop the image width and height are correct in my app. Is this a limitation of Visual Studios Visual Basic?

2

Answers


  1. The reason for the difference is that the other applications are manually applying the correction for Exif.Image.Orientation (tag 274).

    Just inspect this tag and rotate the bitmap accordingly.

    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
    
    Login or Signup to reply.
  2. If you check the orientation property it might help answering/helping your issue with width and height being same when reading photo from Camera output.
    Please let us know your findings.

    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 tags,
    PropertyItem.Id 274

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search