I have a Pixbuf in some demo code I have and I currently rotate it clockwise or counter-clockwise depending on screen touches.
I do this using RotateSimple
but that is limited to multiples of 90 degrees.
Is there a way within GDK to rotate images in Pixbuf buffers by 45 degrees (or less)?
No, not with RotateSimple
(or gdk_pixbuf_rotate_simple()
in the underlying libraries). As per the documentation, that is limited to rotating "by a multiple of 90 degrees".
However, one thing you can do is provide multiple images to make it appear as if you are rotating by a smaller value.
For your specific example of 45 degrees, only two images are needed. The first is the "upright" image for which you can use 90 degree rotations (i.e., using SimpleRotate
) to get four of the eight required rotations, 0
, 90
, 180
and 270
.
To get the other four possibilities, put the image into some image editing software and use that to rotate it 45 degrees, saving it as the "tilted" image.
That way, you can get all of the possibilities by using various rotations of the two images:
Desired rotation Uses image Actual rotation
---------------- ---------- ---------------
0 upright 0
45 tilted 0
90 upright 90
135 tilted 90
180 upright 180
225 tilted 180
270 upright 270
315 tilted 270
For more fine-grained rotations, you can do a similar thing, especially if the resolution of the rotation is some factor of 360. And, thanks to the forward-looking nature of the Babylonians (or Sumerians or someone, my history is a bit rusty), 360 has a rather large number of factors.