Skip to content

Commit 6f08a73

Browse files
committed
Repect image's orientation
1 parent 172fb54 commit 6f08a73

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

crates/egui_extras/src/image.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,23 @@ use egui::SizeHint;
1212
/// On invalid image or unsupported image format.
1313
#[cfg(feature = "image")]
1414
pub fn load_image_bytes(image_bytes: &[u8]) -> Result<egui::ColorImage, egui::load::LoadError> {
15+
fn load_image_with_orientation(image_bytes: &[u8]) -> image::ImageResult<image::DynamicImage> {
16+
use std::io::Cursor;
17+
18+
use image::{DynamicImage, ImageDecoder, ImageReader};
19+
20+
let format = image::guess_format(image_bytes)?;
21+
let reader = Cursor::new(image_bytes);
22+
let reader = ImageReader::with_format(reader, format);
23+
let mut decoder = reader.into_decoder()?;
24+
let orientation = ImageDecoder::orientation(&mut decoder)?;
25+
let mut image = DynamicImage::from_decoder(decoder)?;
26+
image.apply_orientation(orientation);
27+
Ok(image)
28+
}
29+
1530
profiling::function_scope!();
16-
let image = image::load_from_memory(image_bytes).map_err(|err| match err {
31+
let image = load_image_with_orientation(image_bytes).map_err(|err| match err {
1732
image::ImageError::Unsupported(err) => match err.kind() {
1833
image::error::UnsupportedErrorKind::Format(format) => {
1934
egui::load::LoadError::FormatNotSupported {

0 commit comments

Comments
 (0)