gpt4 book ai didi

类型转换 GTK 杂波纹理和普通杂波纹理

转载 作者:行者123 更新时间:2023-11-30 15:58:31 25 4
gpt4 key购买 nike

我在整理一些旧的杂乱代码中的转换时遇到问题,试图使其更新。它有这样的代码:

static void image_init(CtkImage *image)
{
priv->texture = clutter_texture_new ();
...
}

static void refresh_icon (CtkImage *image)
{
CtkImagePrivate *priv = image->priv;
gtk_clutter_texture_set_from_pixbuf (CLUTTER_TEXTURE (priv->texture), priv->pixbuf, NULL);
}

这会产生此编译时错误:

error: passing argument 1 of ‘gtk_clutter_texture_set_from_pixbuf’ from incompatible pointer type [-Werror]
/usr/include/clutter-gtk-1.0/clutter-gtk/gtk-clutter-texture.h:99:17: note: expected ‘struct GtkClutterTexture *’ but argument is of type ‘struct ClutterTexture *’

我认为我可以使用 GTK_CLUTTER_TEXTURE 来修复它,这确实可以编译,但存在运行时错误并且缺少 pixbufs:

gtk_clutter_texture_set_from_pixbuf (GTK_CLUTTER_TEXTURE (texture), tiled, NULL);

结果:

GLib-GObject-WARNING **: invalid cast from `ClutterTexture' to `GtkClutterTexture'

Clutter-Gtk-CRITICAL **: gtk_clutter_texture_set_from_pixbuf: assertion `GTK_CLUTTER_IS_TEXTURE (texture)' failed

发生了什么事,为什么会失败?以及如何调试?

最佳答案

GtkClutterTexture 是 ClutterTexture 的子类;这意味着您可以将 GtkClutterTexture 与接受 ClutterTexture 的每个函数一起使用,但不能将 ClutterTexture 与采用 GtkClutterTexture 的方法一起使用。

在示例中,您使用 clutter_texture_new() 创建纹理,然后将该指针传递给 gtk_clutter_texture_set_from_pixbuf()。您可以创建一个 GtkClutterTexture,或者使用 clutter_texture_set_from_rgb_data() 函数从 GdkPixbuf 设置图像数据,使用类似以下内容:

  clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (texture),
gdk_pixbuf_get_pixels (pixbuf),
gdk_pixbuf_get_has_alpha (pixbuf),
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf),
gdk_pixbuf_get_rowstride (pixbuf),
gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3,
CLUTTER_TEXTURE_NONE,
&gerror);

这正是 GtkClutterTexture.set_from_pixbuf() 所做的。

关于类型转换 GTK 杂波纹理和普通杂波纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9678059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com