I'm trying to render an image (gif/png) on a DrawingArea in gtk-rs. I can read the image file with Pixbuf:
Pixbuf::new_from_file("/path/to/img.gif")
But I cannot find a way to render the Pixbuf into cairo::Context. I noticed that gdk::prelude::ContextExt has set_source_pixbuf():
https://docs.rs/crate/gdk/0.1.4/source/src/cairo_interaction.rs
So I tried to use this:
extern crate gdk;
use gdk::prelude::*;
...
drawingArea.connect_draw(move |widget, context| {
context.set_source_pixbuf(&ws.pix, 0f64, 0f64);
context.stroke();
return Inhibit(false);
});
But nothing is rendered. The ContextExt seems unimplemented (it seems to specify null to the second parameter of gdk_cairo_set_source_pixbuf)?
fn set_source_pixbuf(&self, pixbuf: &Pixbuf, x: f64, y: f64) {
unsafe {
ffi::gdk_cairo_set_source_pixbuf(self.to_glib_none().0, pixbuf.to_glib_none().0, x, y);
}
}
Is there any other method to render an image on DrawingArea?
I need to use Context.paint() instead of Context.stroke():
context.set_source_pixbuf(&ws.pix, 0f64, 0f64);
context.paint(); // need to call paint() instead of stroke().
return Inhibit(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With