Skip to content

Commit

Permalink
πŸ‘©β€πŸ’»(ImageShower): add anti-aliasing option
Browse files Browse the repository at this point in the history
Introduce an `anti_alias` field to the `MyEguiApp` struct and a corresponding toggle in the UI. Update the texture loading to apply linear filtering if anti-aliasing is enabled, enhancing image quality.

Signed-off-by: Benign X <1341398182@qq.com>
  • Loading branch information
W-Mai committed Dec 1, 2024
1 parent ccda814 commit c7571d7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/image_shower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct MyEguiApp {
image_data: Option<Vec<Color32>>,

show_grid: bool,
anti_alias: bool,
}

impl MyEguiApp {
Expand All @@ -54,6 +55,7 @@ impl MyEguiApp {
image_data,

show_grid: true,
anti_alias: true,
}
}
}
Expand All @@ -68,6 +70,7 @@ impl eframe::App for MyEguiApp {
egui::widgets::global_dark_light_mode_switch(ui);
ui.separator();
ui.toggle_value(&mut self.show_grid, "Show Grid");
ui.toggle_value(&mut self.anti_alias, "Anti-Aliases");
});
});
egui::CentralPanel::default().show(ctx, |ui| match &self.image_data {
Expand All @@ -77,9 +80,15 @@ impl eframe::App for MyEguiApp {
size: [self.width as usize, self.height as usize],
pixels: image_data.clone(),
};
let texture = ui
.ctx()
.load_texture("showing_image", image, Default::default());
let texture = ui.ctx().load_texture(
"showing_image",
image,
if self.anti_alias {
egui::TextureOptions::LINEAR
} else {
egui::TextureOptions::NEAREST
},
);

let texture =
SizedTexture::new(texture.id(), [self.width as f32, self.height as f32]);
Expand Down

0 comments on commit c7571d7

Please sign in to comment.