File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,8 +12,23 @@ use egui::SizeHint;
1212/// On invalid image or unsupported image format.
1313#[ cfg( feature = "image" ) ]
1414pub 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 {
You can’t perform that action at this time.
0 commit comments