[cairo] Regarding saving a image surface as PNG
Chandra Shekhar Sengupta
sayan801 at gmail.com
Tue Apr 15 23:11:35 PDT 2008
Hi,
I am new to cairo. i am trying to rotate and scale a image . After doing the
transformation i am displaying it in the window, it is shown properly . But
when i am saving the surface using "cairo_surface_write_to_png" , the
original image is saved again , the changes due to transformation is not
reflected. And when i was trying to get the width of scaled surface using
"cairo_image_surface_get_width", it is giving the original width only.My
code segment is given below.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static gboolean on_expose_event(GtkWidget *widget,GdkEventExpose *event,
gpointer data)
{
cairo_t *cr;
gint width,height;
cr = gdk_cairo_create (widget->window);
width = cairo_image_surface_get_width(image);
height = cairo_image_surface_get_height(image);
cairo_translate(cr,width/2,height/2);
cairo_scale(cr,scale_factor,scale_factor);
cairo_rotate(cr,rotate_angle*M_PI/180.0);
g_print("rotate_angle %f \n",rotate_angle);
gtk_widget_set_size_request (da, width,height);
g_print("width = %d height = %d \n",width,height);
cairo_set_source_surface(cr, image,-width/2,-height/2);
cairo_paint(cr);
cairo_surface_write_to_png (image, "sticker.png");
cairo_destroy(cr);
return FALSE;
}
int main(int argc, char *argv[])
{
/...../
image = cairo_image_surface_create_from_png(argv[1]);
width = cairo_image_surface_get_width(image);
height = cairo_image_surface_get_height(image);
g_print("width = %d height = %d \n",width,height);
/...../
da = gtk_drawing_area_new ();
gtk_widget_set_size_request (da, width,height);
gtk_fixed_put(GTK_FIXED(fixed),da,50,50);
g_signal_connect(da, "expose-event",G_CALLBACK (on_expose_event), NULL);
/...../
cairo_surface_destroy(image);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Thanks in Advance.
Regards,
Chandra Shekhar Sengupta
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080416/00dc7d73/attachment.html
More information about the cairo
mailing list