I'm writing an application with rust-xcb
. However, when I try to load a file into a pixmap I cannot find any way to do it. I also use image
library to load image files (jpg).
But I am not familiar with xcb, is there a way for xcb to load pixel buffers or files into pixmap? Or I can find another library to do this?
I have searched for it. Some document of xcb pixmap and bitmap is full of TODO.
I have tried xcb-util-image
, but didn't find what I need.
My code is below:
let foreground = self.connection.generate_id();
xcb::create_gc(
&self.connection,
foreground,
screen.root(),
&[
(xcb::GC_FOREGROUND, screen.white_pixel()),
(xcb::GC_GRAPHICS_EXPOSURES, 0),
],
);
let mut img = image::open(background_src).unwrap();
let img_width = img.width();
let img_height = img.height();
xcb::create_pixmap(
&self.connection,
24,
pixmap,
self.window_id,
img_width as u16,
img_height as u16,
);
let img_buffer = img.to_rgb().into_raw();
xcb::put_image(
&self.connection,
xcb::IMAGE_FORMAT_Z_PIXMAP as u8,
pixmap,
foreground,
img_width as u16,
img_height as u16,
0,
0,
0,
24,
&img_buffer,
);
self.flush(); // Flush the connection