Replies: 1 comment
-
Hi! I could work around this issue by using the //Get available rect
let available_rect = ui.ctx().available_rect();
//Fetch available size
let available_size = available_rect.size();
//Opcaity
let opacity: u8 = 10;
//Loading the image bytes (You can use any other way you would like)
let img_src = include_bytes!("../image.jpg");
//Load image into memory
let img_mem = image::load_from_memory(img_src).unwrap();
//Fetch image size
let (width, height) = (img_mem.width(), img_mem.height());
//Get the image's aspect ratio
let img_aspect_ratio = width as f32 / height as f32;
//Get the final sizes of the imge
let img_width = available_size.x;
//Multiply with aspect ratio to maintain it
let img_height = img_width / img_aspect_ratio;
//Create egui image instance
let img = Image::from_bytes("image_uri", egui::load::Bytes::Static(img_src));
//Paint the image
img.tint(
//Set opacity
Color32::from_white_alpha(opacity),
)
//paint the tinted image
.paint_at(
ui,
egui::Rect::from_min_size(available_rect.min, Vec2::new(img_width, img_height)),
); I also included the code to modify the opacity of image. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
maintain_aspect_ratio(true)
did not work.and can I modify the opacity of the img?
Beta Was this translation helpful? Give feedback.
All reactions