Hello,
<br>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.
<br>
<br>The code:
<br> cairo_t *cr;
<br> int w, h;
<br> int x_origin, y_origin;
<br>
<br> //Load an image from file
<br> cairo_surface_t *surf1 =
cairo_image_surface_create_from_png("./images/strelka_100_100.png");
<br> w = cairo_image_surface_get_width (surf1);
<br> h = cairo_image_surface_get_height (surf1);
<br>
<br> //Create the cairo context
<br> cr = gdk_cairo_create (widget->window);
<br>
<br> //Initialize the image to white transparent
<br> cairo_set_source_rgba(cr, 0, 0, 0, 1);
<br> cairo_paint(cr);
<br>
<br> x_origin = w/2;
<br> y_origin = h/2;
<br> x_offset = 0;
<br>
<br> cairo_translate (cr, x_origin, y_origin);
<br> cairo_rotate (cr, (2*3.14*angle/360));
<br>
<br> cairo_set_source_surface(cr, surf1, -x_origin+x_offset, -y_origin);
<br> cairo_paint(cr);
<br>
<br>
<br>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.
<br>
<br>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?
<br>
<br>Thanks,
<br>Blagoj