The wpf class System.Windows.Media.Imaging.BitmapDecoder does not read the entire file, only metadata.
using(var imageStream = File.OpenRead("file")) { var decoder = BitmapDecoder.Create(imageStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default); var height = decoder.Frames[0].PixelHeight; var width = decoder.Frames[0].PixelWidth; }
Update 2019-07-07
If I remember correctly, after a few months I found that working with exif images is a little more difficult. For some reason, the iphone saves the rotated image instead of the usual one and sets the flag βrotate this image before displayingβ.
GIF also turned out to be a rather complicated format. It is possible that not a single frame has a full GIF size, you should aggregate it from offsets and frame sizes.
So I used ImageProcessor instead, which handled all the problems for me. I never checked if it reads the whole file, although some browsers do not have exif support, and I still had to save the rotated version.
using (var imageFactory = new ImageFactory()) { imageFactory .Load(stream) .AutoRotate();
Atomosk Jun 27 '16 at 4:15 2016-06-27 04:15
source share