Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Change jpg image exif orientation value
Message
De
09/08/2016 12:38:40
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Photos et traitement d'images
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 8.1
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01639240
Message ID:
01639252
Vues:
167
This message has been marked as the solution to the initial question of the thread.
J'aime (1)
>I need to change the exif orientation value in a JPG image.
>
>Anybody have a code example on how to do this?
>
>I found this: http://www.news2news.com/vfp/?example=461
>
>But the site doesn't work for me (pay for membership to get code) and I'm not getting any replies to email I send.

Start by using / installing the GDIPlusX library at http://vfpx.codeplex.com/wikipage?title=GDIPlusX.

After issuing System.app, you are set to go (no error trapping, nothing fancy, just something to get you started):
LOCAL ExifTargetOrientation AS Integer

* the pretended orientation (left - bottom)
m.ExifTargetOrientation = 0h0800

LOCAL IdExifOrientation AS Integer

m.IdExifOrientation = 0x112

LOCAL JPEGImage

* get a JPEG image from disk
JPEGImage = _Screen.System.Drawing.Image.Fromfile(GETFILE("jpg"))

LOCAL LoopProperties AS Integer
LOCAL ExifOrientation AS Integer

m.ExifOrientation = 0

* locate EXIF orientation setting
FOR m.LoopProperties = 1 TO m.JPEGImage.PropertyItems.Count

	* found it? get its index
	IF m.JPEGImage.PropertyIdList(m.LoopProperties) = m.IdExifOrientation
		m.ExifOrientation = m.LoopProperties
		EXIT
	ENDIF

ENDFOR

* not found...
IF m.ExifOrientation = 0
	MESSAGEBOX("No EXIF orientation settings found in the image")
	RETURN
ENDIF

LOCAL ExifProperty

* get the orientation property
m.ExifProperty = m.JPEGImage.GetPropertyItem(m.IdExifOrientation)

* and check its value - if already set as the target orientation, just leave as it is
IF m.ExifProperty.Value = m.ExifTargetOrientation
	MESSAGEBOX("EXIF orientation already set to " + TRANSFORM(m.ExifTargetOrientation))
	RETURN
ENDIF

* set the target orientation setting and put the property back in the image
m.ExifProperty.Value = m.ExifTargetOrientation
m.JPEGImage.SetPropertyItem(m.ExifProperty)

* save the image
m.JPEGImage.Save(PUTFILE("Reoriented:","reoriented.jpg","jpg"), _Screen.System.Drawing.Imaging.ImageFormat.Jpeg)
----------------------------------
António Tavares Lopes
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform