Results 1 to 20 of 20

Thread: JPEG Auto Rotate Picture Box

Threaded View

  1. #13
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    Lightbulb Re: JPEG Auto Rotate Picture Box

    Quote Originally Posted by boops boops View Post
    OK Paul, as it's you you're not required to grovel (much). Here's a function that returns a correctly oriented image from a digital camera JPEG file:
    .....
    BB
    Ok, sir, i know it's very late, but still, as i come to this thread today, others may come to later also. so, i decided to reply,

    your mentioned code will throw error (or even crash without proper error handling), if the image/file does not have the correct exif tag.

    that's why i added a line to your code and hope it may help noobs like me

    vb.net Code:
    1. Private Function OrientedImageFromFile(ByVal photoFileName As String) As Image
    2.         Dim img As Image = Image.FromFile(photoFileName) 'get the image
    3.         Dim pi As Imaging.PropertyItem = Array.Find(img.PropertyItems, _
    4.              Function(T As Imaging.PropertyItem) T.Id = &H112) '&H112 = PropertyTagOrientation
    5.         If pi IsNot Nothing Then
    6.             Select Case pi.Value(0) 'value is array of Int16
    7.                 Case 3 : img.RotateFlip(RotateFlipType.Rotate180FlipNone) 'upside-down
    8.                 Case 6 : img.RotateFlip(RotateFlipType.Rotate90FlipNone) 'rotated right
    9.                 Case 8 : img.RotateFlip(RotateFlipType.Rotate270FlipNone) 'rotated left
    10.             End Select
    11.         End If
    12.         Return img
    13.     End Function

    hope it may help someone, some day..

    of course nevertheless, thanks for sharing your code.
    Last edited by Shohag_ifas; Sep 30th, 2019 at 08:32 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width