On Wed, May 10, 2006 at 09:29:31AM -0700, temp temp wrote: > I have a problem creating a function that will draw the contents of a buffer > into a drawing area. > > Here is the function I call when I want to draw the contents of "buffer" into > the drawingarea designated by "area": > > int draw_in_widget(GtkWidget *area,unsigned char* buffer,int img_height,int > img_width,bool is_rgb) > { > //conversion BGR->RGB > if(!is_rgb) > { > unsigned char tmp; > for(int i=0;i<img_width*img_height;i++) > { > tmp = buffer[3*i];//B->tmp > buffer[3*i] = buffer[3*i+2];//R->B > buffer[3*i+2] = tmp;//tmp->R > } > } > > gpointer destroy_fn_data; > int area_width=area->allocation.width; > int area_height=area->allocation.height; > > GdkPixbuf *pixbuf_dest=gdk_pixbuf_new(GDK_COLORSPACE_RGB,FALSE,8, > area_width,area_height); > GdkPixbuf > *pixbuf_src=gdk_pixbuf_new_from_data(buffer,GDK_COLORSPACE_RGB,FALSE,8, > img_width,img_height,img_width*3,NULL,destroy_fn_data); > GdkGC *gc=area->style->fg_gc[GTK_STATE_NORMAL]; > double scale_x=(double)area_width/img_width; > double scale_y=(double)area_height/img_height; > > gtk_widget_queue_draw(area);
You should not call gtk_widget_queue_draw() on a widget in its expose handler. I wonder how the redrawing ever stops when each redraw attempts to invoke another redraw... > gdk_pixbuf_scale(pixbuf_src,pixbuf_dest,0,0,area_width,area_height, > 0,0,scale_x,scale_y,GDK_INTERP_TILES); > > gdk_draw_pixbuf(area->window,gc,pixbuf_dest, > 0,0,0,0,area_width,area_height,GDK_RGB_DITHER_NORMAL,0,0); > > gdk_pixbuf_unref(pixbuf_src); > gdk_pixbuf_unref(pixbuf_dest); > return(0); > } > > > The function adapts the size of the image contained in the buffer (of size > 3*img_height*img_width) to the size of the drawing area. > > My problem is that this function only works when placed in a > "on_drawingarea1_expose_event" handler. To invoke redraw of a widget call gtk_widget_queue_draw(widget); As a result, the expose handler will be called (somewhat later when the main loop comes to that). Yeti -- Anonyms eat their boogers. _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list