[英]Is there a way for xcb to load a file into a pixmap?
我正在用rust-xcb
編寫應用程序。 但是,當我嘗試將文件加載到像素圖中時,找不到任何方法。 我還使用image
庫加載圖像文件(jpg)。
但是我不熟悉xcb,xcb是否可以將像素緩沖區或文件加載到pixmap中? 或者我可以找到另一個圖書館來做到這一點?
我已經搜尋了。 xcb像素圖和位圖的某些文檔充滿了TODO。 我嘗試了xcb-util-image
,但是沒有找到我需要的東西。
我的代碼如下:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.