[cairo] Regarding saving a image surface as PNG

Gerdus van Zyl gerdusvanzyl at gmail.com
Wed Apr 16 03:04:00 PDT 2008


Its because you are not working with the surface cr is targeting. You need
code like
tsurf = cairo_get_target(cr); to get the temporary surface GTK is giving
you.

~Gerdus

On Wed, Apr 16, 2008 at 8:11 AM, Chandra Shekhar Sengupta <
sayan801 at gmail.com> wrote:

> 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
>
>
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080416/101b7551/attachment.html 


More information about the cairo mailing list