我尝试在gtk-rs中的DrawingArea上渲染一个图像(gif/png)。我可以用Pixbuf读取图像文件
Pixbuf::new_from_file("/path/to/img.gif")但是我找不到一种将Pixbuf呈现为cairo::Context的方法。我注意到gdk::prelude::ContextExt有set_source_pixbuf()
https://docs.rs/crate/gdk/0.1.4/source/src/cairo_interaction.rs
所以我试着用这个:
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);
});但不会渲染任何内容。ContextExt似乎未实现(它似乎为gdk_cairo_set_source_pixbuf的第二个参数指定了null )?
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);
}
}有没有其他方法可以在DrawingArea上渲染图像?
发布于 2017-01-13 09:35:15
我需要使用Context.paint()而不是Context.stroke()
context.set_source_pixbuf(&ws.pix, 0f64, 0f64);
context.paint(); // need to call paint() instead of stroke().
return Inhibit(false);https://stackoverflow.com/questions/41610274
复制相似问题