The resized JPG file is rotated 90 degrees clockwise.
I suspect, for what I investigated, that the problem could be solved looking at the EXIF metadata in the JPG and depends on that it could need or not a rotation.
I couldn’t find a method to evaluate the EXIF metadata and if needed rotate the JPG.
May be @Christian_Schmitz could give some advice with a method CorrectOrientation using MBS plugins or someone else in the forum using only pure Xojo functions.
You’re certainly right about the exif data (or whatever equivalent for jpeg pictures). Graphics.DrawPicture may not retain the existing data. Now, is this a bug or a limitation?
A JPEG file contains compressed picture data and metadata – JPEG-specific metadata, Exif metadata, possibly other kinds of metadata such as IPTC. A Picture object in Xojo contains only (uncompressed) picture data. While reading the picture data from the file Xojo uses the orientation metadata and rotates the picture data accordingly but the Picture object itself doesn’t contain those metadata.
Like I said: Picture is for picture data, not metadata. There are all kinds of metadata that could be stored in image files and it wouldn’t make much sense to store all of these in a Picture object.
Right, I should have said “keep the metadata in another class, possibly a property of the picture”.
In all means, we (Xojo users) should be able to deal with the metadata, especially when the ignored data produce a picture that gets rotated.
But it isn’t ignored – not under macOS anyway and I would be surprised if this was an issue under Windows. Having said that there could be an issue with conflicting orientation tags as there can be more than one (just like there is more than just one kind of metadata).
I guess Xojo is trying to hide the complexity for us, but if we can’t retrieve the orientation, how can we deal with using DrawPicture (for instance), where the orientation is reset?
Not to go off the thread too much, but on OSX you can call mdls from a shell to get a file’s metadata and for an image file this has the exif data.
Regards - Richard.
@Michael_Hußmann Thanks for your response. I forgot to say that I am using XOJO 2019 and on that version Translate and Rotate are not members of Graphics type.
Public Function RotateClockwise90Degrees(aPicture as Picture) As Picture
var originalWidth as Integer = aPicture.Width
var maxX as Integer = originalWidth - 1
var originalHeight as Integer = aPicture.Height
var maxY as Integer = originalHeight - 1
var rotatedPicture as new Picture(originalHeight, originalWidth)
var originalRGBSurface as RGBSurface = aPicture.RGBSurface
var rotatedRGBSurface as RGBSurface = rotatedPicture.RGBSurface
var x, y as Integer
for y = 0 to maxY
for x = 0 to maxX
rotatedRGBSurface.Pixel(maxY - y, maxX - x) = originalRGBSurface.Pixel(x, y)
next x
next y
return rotatedPicture
End Function
dim options as new Dictionary
options.Value(CGImageSourceMBS.kCGImageSourceThumbnailMaxPixelSize) = myPreviewSize
options.Value(CGImageSourceMBS.kCGImageSourceCreateThumbnailFromImageAlways) = true
options.Value(CGImageSourceMBS.kCGImageSourceCreateThumbnailWithTransform) = True
dim theCGImage as CGImageMBS = CGImageSourceMBS.CreateThumbnailMT(MimeData, 0, options)
PreviewPic = theCGImage.Picture
In general the images show up rotated 180 degrees. And yes, this should be handled by Xojo.
Have we established that it isn’t? Under Windows that is, because under macOS, Xojo does respect orientation tags and can deal with rotated pictures just fine.
In the project I’m working on (under macOS) I’m dealing with all kinds of pictures from various sources and they all open with the correct orientation; resizing (I’m creating scaled down previews and thumbnails) doesn’t change that.
As I was curious I took a photograph with my iPhone, first in landscape orientation, then in portrait orientation, then again in landscape orientation, but I rotated it in the Photos app. All three JPEG files had the correct orientation tag in their Exif data (default – i.e. landscape –, portrait, and again portrait) and they were opened by Xojo in the correct orientation as specified by those tags.
In the MBS plugins, you can often make use of the GraphicsMagik functions to detect the orientation, and to rotate.
//rotation
dim p as picture = somepicture.Rotate90MBS
//orientation
dim gorig as GMImageMBS
try
gorig = new GMImageMBS(f)
catch
end try
if gorig <> nil then
try
gorig.autoOrient //detect orientation info and auto rotate to compensate
catch
end try
end if