|
-
Sep 30th, 2019, 08:27 AM
#13
Hyperactive Member
Re: JPEG Auto Rotate Picture Box
 Originally Posted by boops boops
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:
Private Function OrientedImageFromFile(ByVal photoFileName As String) As Image
Dim img As Image = Image.FromFile(photoFileName) 'get the image
Dim pi As Imaging.PropertyItem = Array.Find(img.PropertyItems, _
Function(T As Imaging.PropertyItem) T.Id = &H112) '&H112 = PropertyTagOrientation
If pi IsNot Nothing Then
Select Case pi.Value(0) 'value is array of Int16
Case 3 : img.RotateFlip(RotateFlipType.Rotate180FlipNone) 'upside-down
Case 6 : img.RotateFlip(RotateFlipType.Rotate90FlipNone) 'rotated right
Case 8 : img.RotateFlip(RotateFlipType.Rotate270FlipNone) 'rotated left
End Select
End If
Return img
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|