GtkStatusIcon绘图问题
我在 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" - .
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_colormapGdk-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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经用解决方法解决了我的问题。问题在于创建像素图 - 它从“诞生”起就“肮脏”。解决方案是不使用 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