gdk_draw_pixbuf: assertion 'GDK_IS_DRAWABLE(drawable)'failed
正在学习使用gdk_draw_pixbuf和gdk_pixbuf_new_from_data两个函数,自己编写了一个例子如下:
#include <gtk/gtk.h>
#include <stdlib.h>
void close_application( GtkWidget *widget, GdkEvent *event, gpointer data )
{
gtk_main_quit();
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GdkPixbuf *pixbuf;
GtkWidget *draw_able;
guchar *frame_data=(guchar *)malloc(sizeof(guchar) *640*480 * 3);
int i;
gtk_init (&argc, &argv);
window = gtk_window_new( GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (close_application), NULL);
draw_able = gtk_drawing_area_new ();
gtk_widget_set_size_request (draw_able, 320, 240);
gtk_container_add (GTK_CONTAINER (window), draw_able);
for (i=0; i<640*480*3;i++)
{ frame_data=0x00;}
pixbuf = gdk_pixbuf_new_from_data ( frame_data, GDK_COLORSPACE_RGB, FALSE,8,640,480, 640*3,0,0);
gdk_draw_pixbuf ( GTK_WIDGET (draw_able)->window, NULL,pixbuf,0,0,0,0, 320,240, GDK_RGB_DITHER_NORMAL, 0, 0);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
运行的时出现错误:Gdk_CRITICAL **: gdk_draw_pixbuf: assertion 'GDK_IS_DRAWABLE(drawable)'failed有谁知道的帮忙解决下,先谢过了
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Thx
Description
The GtkDrawingArea widget is used for creating custom user interface elements. It's essentially a blank widget; you can draw on widget->window. After creating a drawing area, the application may want to connect to:
*
Mouse and button press signals to respond to input from the user. (Use gtk_widget_add_events() to enable events you wish to receive.)
*
The "realize" signal to take any necessary actions when the widget is instantiated on a particular display. (Create GDK resources in response to this signal.)
*
The "configure_event" signal to take any necessary actions when the widget changes size.
*
The "expose_event" signal to handle redrawing the contents of the widget.
drawarea应该是在expose的事件中去画的。
怎么还是报一样的错?
在你的gdk_draw_pixbuf()前面加一句 gtk_widget_realize(draw_able);就ok了