|
-
Nov 20th, 2010, 07:28 AM
#1
Thread Starter
Addicted Member
JPEG Auto Rotate Picture Box
Hi .
My project have a Picture box control for loading pictures but it's worked fine
my problem is...
some vertical Jpg picture was shown Horizontally in windows explorer and also my picutre box control at that same that file was opened with vertically in editors like photoshop . but i need not picture rotate codes i want to Vertical picture was shown as vertically into my picture box control is't possible,
please help me.
..........SORRY FOR MY POOR ENGLISH...
Thanks
-
Nov 20th, 2010, 07:44 AM
#2
Re: JPEG Auto Rotate Picture Box
The image will be displayed in a PictureBox with its original orientation. For instance, if you rotate a camera 90 degrees to take a photo, the resulting image will be displayed rotated by 90 degrees. The image doesn't know that you want it to be rotated. Some image editing software may be smart enough to recognise such images and rotate them automatically, but the logic to do that is very, very sophisticated. If you want a VB app to display an image rotated by 90 degrees then you have to specifically code it to do so. Also, it cannot be done by setting the Image of a PictureBox. You would have to draw the Image yourself using GDI+, transforming a Graphics object first. E.g.
http://www.vbforums.com/showthread.p...otatetransform
-
Nov 20th, 2010, 07:59 AM
#3
Thread Starter
Addicted Member
Re: JPEG Auto Rotate Picture Box
Thank You Mr jmcilhinney 
Thanks for your nice informations...........
-
Nov 20th, 2010, 08:58 AM
#4
Re: JPEG Auto Rotate Picture Box
It's easier to do it with an Image.RotateFlip statement:
Code:
'to rotate 90 degrees clockwise:
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
'to rotate 90 degrees anticlockwise:
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone)
BB
-
Nov 20th, 2010, 09:35 AM
#5
Re: JPEG Auto Rotate Picture Box
 Originally Posted by boops boops
It's easier to do it with an Image.RotateFlip statement:
Code:
'to rotate 90 degrees clockwise:
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
'to rotate 90 degrees anticlockwise:
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone)
BB
Good point. I forgot that that was available for multiples of 90 degrees.
Do keep in mind that the change only affects the current Image object, so if you want to update the original file then you would have to call its Save method.
-
Nov 20th, 2010, 10:38 AM
#6
Re: JPEG Auto Rotate Picture Box
 Originally Posted by boops boops
It's easier to do it with an Image.RotateFlip statement:
Code:
'to rotate 90 degrees clockwise:
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
'to rotate 90 degrees anticlockwise:
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone)
BB
i was going to say...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 20th, 2010, 11:03 AM
#7
Thread Starter
Addicted Member
Re: JPEG Auto Rotate Picture Box
Hello Friends. thanks for your reply's
this is my need.......a folder contain 100 wedding photos lot of Horizontal and vertical(it's show horizontally in WIndows Explorer Thumbnail Mode but in Image Editor shows Vertically) orientation
so i want to find out how much Horizontal and Vertical photos are in this folder.
'to rotate 90 degrees clockwise:
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
'to rotate 90 degrees anticlockwise:
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone)
how can use this code to find HV orientation contain 100 Files Folder............
Thanks..............
-
Nov 20th, 2010, 12:55 PM
#8
Re: JPEG Auto Rotate Picture Box
Hi medsont,
The code I gave you only turns the image in the picture box. It doesn't find the orientation. To do that, you have to analyse the EXIF data which digital cameras store in their JPEG images.
In VB.Net, EXIF data is found in the class Imaging.PropertyItems. I have used that myself for getting embedded thumbnails but I haven't tried it yet for getting orientation information. Still, it's something I would like to do, and I know it's possible, so I'll see if I can work out some code. In the meantime, if anyone else has a readymade solution ... please post!
BB
-
Nov 20th, 2010, 01:46 PM
#9
Thread Starter
Addicted Member
Re: JPEG Auto Rotate Picture Box
Hey Boops Boops thanks for your great reply i solved my problem myself i am very glad to post here
ya i got the Orientation flag from the Exif data and rotated my pictures, yup thanks for your nice info
today i will sleep with good dreams.........
Thanks for your great helps...............
-
Nov 20th, 2010, 02:28 PM
#10
Re: JPEG Auto Rotate Picture Box
Great. And now I have my own version working too. If anyone wants to know how it's done, all they have to do is beg . BB
-
Nov 20th, 2010, 02:49 PM
#11
Re: JPEG Auto Rotate Picture Box
ok boops, i'm begging howto?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 20th, 2010, 03:10 PM
#12
Re: JPEG Auto Rotate Picture Box
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:
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
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
Return img
End Function
BB
-
Nov 20th, 2010, 03:42 PM
#13
Re: JPEG Auto Rotate Picture Box
it doesn't work with jpg's from my nokia.
pi.value always =
(0)1
(1)0
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 20th, 2010, 03:55 PM
#14
Re: JPEG Auto Rotate Picture Box
i did some research. i can't fault your code. must be my jpg
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 20th, 2010, 04:01 PM
#15
Re: JPEG Auto Rotate Picture Box
Now Paul, don't they have real cameras in Chelmsford ? It looks like your Nokia doesn't write EXIF data, or at least not the Orientation field.
I've only tried it with my own camera (Panasonic FZ50) but I should think all recent cameras get at least the orientation right. To come to think of it, the last time I saw images wrongly oriented in Windows Explorer they were from a mobile phone. I wonder if phones have their own way of encoding orientation?
BB
-
Nov 20th, 2010, 04:07 PM
#16
Re: JPEG Auto Rotate Picture Box
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 22nd, 2010, 12:29 AM
#17
Thread Starter
Addicted Member
Re: JPEG Auto Rotate Picture Box
hey paul do you want to EXIF binary .......you can modify and edit Exif data. and save .............
-
Nov 22nd, 2010, 09:52 AM
#18
Re: JPEG Auto Rotate Picture Box
 Originally Posted by medsont
hey paul do you want to EXIF binary .......you can modify and edit Exif data. and save .............
no. the images i was using don't contain orientation values
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 30th, 2019, 08:27 AM
#19
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.
-
Sep 30th, 2019, 10:50 AM
#20
Re: JPEG Auto Rotate Picture Box
The function could certainly be better designed, but I don't think a missing exif tag is the problem: If pi IsNot Nothing deals with that. But if I were writing the Function now I would leave Image.FromFile out and pass the Image as an argument instead of the file name. Image.FromFile would belong a separate Sub or Function, where it should get some extra care such as checking the file extension first (*.jpg, *.jpeg etc.) and Try...Catch to protect against an incorrect file format. BB
[edit]I just realized I was looking at the wrong code. You added If pi IsNot Nothing yourself, and I agree it's better.
Last edited by boops boops; Sep 30th, 2019 at 08:41 PM.
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
|