Rotating an image (watch the white rect with a small blue rect below), my image goes out of view (mostly), far more than what GIMP do (image below). The yellow part is… outside of the real image (was grey, but was a bit misleading).
The example in the documentation is useless.
I checked the release notes, found the Feature request (this one have nice artwork Xojo: Account Login).
I’ve created a method that receive the Angle value for the rotation in °.
But I do not know how to get the result width and height to create a larger Picture to draw the rotated image into (so I will not loose parts of the rotated image).
I also want to be able to set the rotated image “centered”, but how do I do that (too) ?
In GIMP, I get that (for example) when asking for a 45° rotation:
So you want to make this in Xojo, right? (you didn’t specify)
You have several possibilities to end up with a picture of the correct size:
• Use the MBS plugin which has Picture.RotateMBS. This function returns a new picture with a size covering the entire result.
• Compute the new size the rotated picture will take (it’s just geometry; sinus, cosinus, pythagorean theorem). Then make a new picture with this size and draw the rotated picture there.
• Have a large picture with width and height being equal to the biggest size (width or height of the source, so you have a squared picture) and you draw there.
Solution 1 is costly, solution 2 may be resource intensive (you create a picture each time you rotate a given picture) and solution 3 uses picture with unnecessary wasted space; beyond that, surely one fits your needs and the undesirable effects would be mostly irrelevant if you choose the best for you.
It depends on your source pictures. Normally, you’d either do one of these:
• if you draw a picture into another one, use Graphics.DrawPicture with x=BackPicture.Width/2-PictureToAdd.Width/2 and y=BackPicture.Height/2-PictureToAdd.Height/2.
• If you draw it yourself without a buffering picture, you have to compute yourself, considering you know the width and height of what you draw.
I can’t say more without knowing how and where you draw.
With a rotation of 45 degrees, parts of the image are outside of the image in order to fully display the image sizes, I reduce with scale
the picture
here when saving to an empty image Object so that the background
is transparent.
Var f As FolderItem
Var neu As New picture(px.Width,px.height)
f = FolderItem.ShowsaveFileDialog(“”,“Mein Bild.png”)
If f <> Nil Then
px.scale = Textscalepx.Text.Val/100 // px.scale 80% passt bei 45°
neu.Graphics.drawobject(px,px.Width/2+centerx.Text.Val,px.height/2+centery.Text.Val)
neu.save(f,picture.SaveAsPNG)