GtkStatusIcon绘图问题

发布于 2024-12-06 22:41:11 字数 1443 浏览 1 评论 0原文

我在 C 中使用 gtk+-2.0,并且我必须在托盘图标上写一个数字。我这样做是这样的:

 static GdkPixbuf * transform_pixbuf(GdkPixbuf *pixbuf) {
    cairo_t *cr;

    int width = gdk_pixbuf_get_width(pixbuf);
    int height = gdk_pixbuf_get_height(pixbuf);

    GdkPixmap *pixmap = gdk_pixmap_new(NULL, width, height, 24);
    cr = gdk_cairo_create(pixmap);
    gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
    cairo_paint(cr);  

    cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, 15.0);
    cairo_set_source_rgb (cr, 1.0, 0, 0); 
    cairo_move_to (cr, 10, 20);
    cairo_show_text (cr, "8");

    cairo_destroy(cr);

    GdkPixbuf *pixbuf_new = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL,
        0, 0, 0, 0, width, height);

    return pixbuf_new;
  }

其中 GdkPixbuf *pixbuf 是我想在托盘中设置的 GdkPixbuf。我可以画一个数字,但图标的背景变成了“跳舞” - 在此处输入图像描述

我猜问题出在 gdk_pixmap_new深度 参数中,因为图标具有 32 位格式,但 32 不是该函数的有效参数。在这种情况下,我有以下警告并且托盘中没有图标:

Gdk-警告 **:使用 Cairo 渲染需要使用可绘制参数 有指定的颜色图。所有窗口都有一个颜色图, 然而,像素图默认只有颜色图,如果它们 使用非 NULL 窗口参数创建。否则 必须使用 gdk_drawable_set_colormap 在它们上设置颜色图

Gdk-警告 **:/build/buildd/gtk+2.0-2.24.4/gdk/gdkpixbuf-drawable.c:1249:源可绘制对象没有颜色图;要么传入颜色图,要么使用 gdk_drawable_set_colormap() 在可绘制对象上设置颜色图

,请建议我...

i'm using gtk+-2.0 in C. and i have to write a digit upon my tray icon. i do it such way:

 static GdkPixbuf * transform_pixbuf(GdkPixbuf *pixbuf) {
    cairo_t *cr;

    int width = gdk_pixbuf_get_width(pixbuf);
    int height = gdk_pixbuf_get_height(pixbuf);

    GdkPixmap *pixmap = gdk_pixmap_new(NULL, width, height, 24);
    cr = gdk_cairo_create(pixmap);
    gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
    cairo_paint(cr);  

    cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, 15.0);
    cairo_set_source_rgb (cr, 1.0, 0, 0); 
    cairo_move_to (cr, 10, 20);
    cairo_show_text (cr, "8");

    cairo_destroy(cr);

    GdkPixbuf *pixbuf_new = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL,
        0, 0, 0, 0, width, height);

    return pixbuf_new;
  }

where GdkPixbuf *pixbuf is GdkPixbuf i want to set in tray. i can draw a digit, but the icon's background became "dancing" - enter image description here.

i guess the problem is in gdk_pixmap_new's depth argument, because the icon has 32bit format, but 32 isn't valid argument for this function. in such case i have followin warning and no icon in the tray:

Gdk-WARNING **: Using Cairo rendering requires the drawable argument to
have a specified colormap. All windows have a colormap,
however, pixmaps only have colormap by default if they
were created with a non-NULL window argument. Otherwise
a colormap must be set on them with gdk_drawable_set_colormap

Gdk-WARNING **: /build/buildd/gtk+2.0-2.24.4/gdk/gdkpixbuf-drawable.c:1249: Source drawable has no colormap; either pass in a colormap, or set the colormap on the drawable with gdk_drawable_set_colormap()

Suggest me, please...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

佞臣 2024-12-13 22:41:11

我已经用解决方法解决了我的问题。问题在于创建像素图 - 它从“诞生”起就“肮脏”。解决方案是不使用 pixmap,而是通过以下函数创建 cairo 上下文: http:// www.gtkforums.com/viewtopic.php?t=5204

i've solved my problem with workaround. the problem was in creating pixmap - it was "dirty" from it's "born". the solution is in to not use pixmap, but create cairo context via the functions: http://www.gtkforums.com/viewtopic.php?t=5204

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文