Clutter.Image Properties — Loading an image from disk

旧巷老猫 提交于 2020-01-06 12:47:43

问题


Using Javascript, and thus remarkably terrible introspection documentation, I am attempting to create a ClutterImage which is supposed to replace the deprecated ClutterTexture. I cannot determine the Property name to use to specify a filename/uri to load for such an image:

const Clutter = imports.gi.Clutter;

Clutter.init(null);

let stage = new Clutter.Stage();

stage.connect("destroy", Clutter.main_quit);
stage.title = "Test";

stage.set_background_color(new Clutter.Color({
    red  : 0,
    blue : 128,
    green : 64,
    alpha : 255
}));

let img = new Clutter.Image({
    uri : 'some-image.jpg'
});

stage.add_actor(img);
Clutter.main();

My error is currently: Error: No property uri on this GObject ClutterImage which of course means that I have an invalid name for a property I'm trying to use for the uri. Does anyone know where I can look this up, or know what the filename/uri property is called in ClutterImages?


回答1:


there is no property or function for loading texture data from file to a Clutter.Image instance.

you should use Gdk.Pixbuf to load the image data from file, buffer, or stream, and then put it in a Clutter.Image with something like:

let pixbuf = Gdk.Pixbuf.new_from_file('...');
let image = new Clutter.Image();
image.set_data(pixbuf.get_pixels(),
               pixbuf.has_alpha() ? Cogl.PixelFormat.RGBA_8888
                                  : Cogl.PixelFormat.RGB_888,
               pixbuf.get_width(),
               pixbuf.get_height(),
               pixbuf.get_rowstride());

which should work; if it doesn't, then it's an introspection issue, and will likely need some tweaks in GdkPixbuf.



来源:https://stackoverflow.com/questions/16946578/clutter-image-properties-loading-an-image-from-disk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!