Hi ,<br>i have tried with adding "get_target" in all possible places, but still "write_png" is saving zero byte png.i have attched the full code . Could you tell how to save that surface?<br><br>////////////////////////////////////////////////////////////////////////////////////////<br>
cairo_surface_t *image,*tsurf;<br>static gdouble rotate_angle = 30.0,scale_factor = 1.5;<br>GtkWidget* da;<br><br><br>static gboolean<br>on_expose_event(GtkWidget *widget,<br> GdkEventExpose *event,<br> gpointer data)<br>
{<br> cairo_t *cr;<br>gint width,height;<br><br>cr = gdk_cairo_create (widget->window);<br><br>width = cairo_image_surface_get_width(image);<br>height = cairo_image_surface_get_height(image);<br> <br>cairo_translate(cr,width/2,height/2);<br>
cairo_scale(cr,scale_factor,scale_factor);<br>cairo_rotate(cr,rotate_angle*M_PI/180.0);<br><br>gtk_widget_set_size_request (da, width*scale_factor,height*scale_factor);<br><br> cairo_set_source_surface(cr, image,-width/2,-height/2);<br>
cairo_paint(cr); <br> tsurf = cairo_get_target(cr);<br><br>if(cairo_surface_status(tsurf) != CAIRO_STATUS_SUCCESS)<br> g_print(" nil surface \n");<br>else<br> cairo_surface_write_to_png (tsurf, "sticker.png");<br>
cairo_destroy(cr);<br><br> return FALSE;<br>}<br><br><br>int main(int argc, char *argv[])<br>{<br> GtkWidget *window;<br> GtkWidget *fixed,*image1;<br> gint width,height;<br><br> image = cairo_image_surface_create_from_png(argv[1]);<br>
width = cairo_image_surface_get_width(image);<br> height = cairo_image_surface_get_height(image);<br> g_print("width = %d height = %d \n",width,height);<br><br> gtk_init(&argc, &argv);<br><br>window = gtk_window_new(GTK_WINDOW_TOPLEVEL);<br>
g_signal_connect(window, "destroy",<br> G_CALLBACK (gtk_main_quit), NULL);<br>gtk_window_set_default_size(GTK_WINDOW(window), 800, 480); <br>gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);<br>
<br>fixed=gtk_fixed_new();<br>gtk_container_add(GTK_CONTAINER(window),fixed);<br><br>image1=gtk_image_new_from_file("bg.png");<br>gtk_fixed_put(GTK_FIXED(fixed),image1,0,0);<br><br>da = gtk_drawing_area_new ();<br>
gtk_widget_set_size_request (da, width*2,height*2);<br>gtk_fixed_put(GTK_FIXED(fixed),da,50,50);<br>g_signal_connect(da, "expose-event",G_CALLBACK (on_expose_event), NULL);<br> <br>gtk_widget_show_all(window);<br>
<br>gtk_main();<br><br>cairo_surface_destroy(image);<br><br> return 0;<br>}<br> <br>///////////////////////////////////////////////////////////////////<br><br><div class="gmail_quote">On Wed, Apr 16, 2008 at 6:32 PM, Gerdus van Zyl <<a href="mailto:gerdusvanzyl@gmail.com">gerdusvanzyl@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">You can use get_target anywhere in on_expose, the write_to_png should be where it is now, after all painting is done before destroy. <br>
<div><div></div><div class="Wj3C7c"><br></div></div></blockquote></div>