免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7382 | 回复: 5
打印 上一主题 下一主题

gdk_draw_pixbuf: assertion 'GDK_IS_DRAWABLE(drawable)'failed [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-10 09:56 |只看该作者 |倒序浏览
正在学习使用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有谁知道的帮忙解决下,先谢过了

论坛徽章:
0
2 [报告]
发表于 2008-04-12 10:32 |只看该作者

回复 #1 87344118 的帖子

在你的gdk_draw_pixbuf()前面加一句 gtk_widget_realize(draw_able);就ok了

论坛徽章:
0
3 [报告]
发表于 2010-03-18 10:53 |只看该作者
在你的gdk_draw_pixbuf()前面加一句 gtk_widget_realize(draw_able);就ok了
biach 发表于 2008-04-12 10:32


怎么还是报一样的错?

论坛徽章:
0
4 [报告]
发表于 2010-03-18 13:41 |只看该作者
drawarea应该是在expose的事件中去画的。

论坛徽章:
0
5 [报告]
发表于 2010-03-18 13:42 |只看该作者
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.

论坛徽章:
0
6 [报告]
发表于 2010-03-19 11:57 |只看该作者
Thx
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP