簡體   English   中英

我怎么可能不能使用這個 function?

[英]How is it possible that i cant use this function?

使用這個 github repo 作為參考: https://github.com/emilk/egui/blob/master/examples/retained_image/src/main.rs

我試圖使用 egui_extras::RetainedImage 將圖像加載到我的框架中,但它給我一個錯誤,即在 RetainedImage 中找不到 function RetainedImage::from_image_bytes。

我還檢查了 image.rs class 以確保 function 確實存在。

這是我的代碼:

use eframe::{run_native, epi::App, egui, NativeOptions};
use egui_extras::RetainedImage;
struct InitView {
    image: RetainedImage,
    tint: egui::Color32,
}

impl Default for InitView {
    fn default() -> Self {
        Self {
            image: RetainedImage::from_image_bytes(
                "date_backdrop.png",
                include_bytes!("date_backdrop.png"),
            )
            .unwrap(),
            tint: egui::Color32::from_rgb(255, 0, 255),
        }
    }
}


impl App for InitView {
    fn name(&self) -> &str {
        "CheckIt"
    }

    fn update(&mut self,ctx: &eframe::egui::CtxRef,frame: &mut eframe::epi::Frame<'_>) {
        //background color
        let frame = egui::containers::Frame {
            fill: egui::Color32::from_rgb(241, 233, 218),
            ..Default::default()
        };
    
        //main window
        egui::CentralPanel::default().frame(frame).show(ctx, |ui| {
            ui.label("test");
        });
    }
}

fn main(){
    let app: InitView = InitView{..Default::default()};
    let win_options = eframe::NativeOptions{
        initial_window_size: Some(egui::Vec2::new(386.0, 636.0)),
        always_on_top: true,
        resizable: false,
        ..Default::default()
    };
    run_native(Box::new(app), win_options);
}

我做錯了什么? 我還是 rust 的新手

您需要添加image功能。

編輯Cargo.toml並將egui_extras替換為egui_extras = { version = "0.20.0", features = ["image"] }或在項目根目錄中運行cargo add egui_extras -F "image"

暫無
暫無

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

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