[cairo] Unsymmetrical rotation
Blagoj Kupev
bkupev at gmail.com
Sun Mar 3 06:33:10 PST 2013
Hello,
I'm trying to rotate a png image with origin in the centre of the image and
then try to put it to a gtk window with offset, but the placement does not
work as I'm expecting.
The code:
cairo_t *cr;
int w, h;
int x_origin, y_origin;
//Load an image from file
cairo_surface_t *surf1 =
cairo_image_surface_create_from_png("./images/strelka_100_100.png");
w = cairo_image_surface_get_width (surf1);
h = cairo_image_surface_get_height (surf1);
//Create the cairo context
cr = gdk_cairo_create (widget->window);
//Initialize the image to white transparent
cairo_set_source_rgba(cr, 0, 0, 0, 1);
cairo_paint(cr);
x_origin = w/2;
y_origin = h/2;
x_offset = 0;
cairo_translate (cr, x_origin, y_origin);
cairo_rotate (cr, (2*3.14*angle/360));
cairo_set_source_surface(cr, surf1, -x_origin+x_offset, -y_origin);
cairo_paint(cr);
In this case for any angle the rotated image starts from the top left
corner and is symmetrical. But if I try to set value different than 0 in
x_offset the position of the image is offset differently according to the
angle. So if i set x_offset = 50 and angle = 20; then the image is moved
not only in x direction but in y as well. For same offset but different
angle the image is placed at different x and y offsets.
So, I'm wondering how to rotate the image and set it with offset that is
different than 0 and the image is always placed there regardless of the
value set in angle?
Thanks,
Blagoj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130303/cace4232/attachment.html>
More information about the cairo
mailing list