0

I need another way than the code below to load image's size and orientation (if any is set). I am using WPF.

There are two problems with this code:

  1. It loads the whole image so it both takes time and memory (especially on large images)

  2. If the image is too large, it will just crash with an unknown exception, assuming it was an out of memory one

            using (FileStream imageStream = File.OpenRead(path))
            {
                using (System.Drawing.Image img = System.Drawing.Image.FromStream(imageStream))
                {
                    Rotation imgRotation = GetImageOreintation(img);//get rotation
    
                    itemData.ImageWidth = img.Width;
                    itemData.ImageHeight = img.Height;
                    itemData.ImageOrientation = imgRotation;
    
                    if (imgRotation != Rotation.Rotate0)
                        imgTemp.Rotation = imgRotation;
                }
            }
    
Nevaran
  • 137
  • 9
  • Why not just use something that is already done instead of re-inventing the wheel? @Clemens correct it is, but nothing stopping someone from adding the libraries needed though.... do I condone this, **no**. – Trevor Feb 10 '20 at 21:11
  • @ΩmegaMan it does not. Using BitmapImage already, but it does not have the orientation property, nor does it have reliable width and height (if it is changed using decoding, the one loaded's size will not be the same) – Nevaran Feb 10 '20 at 21:21

0 Answers0