簡體   English   中英

xcb是否可以將文件加載到像素圖中?

[英]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

根據XCB文檔,像素映射和窗口都是可繪制的: https ://xcb.freedesktop.org/colorsandpixmaps/(“在窗口或像素映射上相同的操作都帶有xcb_drawable_t參數”)

因此,一旦創建了Pixmap,就將其作為第三個參數傳遞給put_image 無需擔心將Pixmap轉換為Drawable; 它們都只是在您的終端上鍵入u32別名,並且都在X服務器的終端上使用相同的ID空間(正如同一份文檔所說,“像素圖基本上是一個不顯示在屏幕上的窗口” )。

要生成data參數中包含的內容,可能只需執行與libpng源相同的操作,但使用Rust而不是C。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM