Created
February 18, 2015 15:06
-
-
Save dejanstojanovic/c5df7310174b570c16bc to your computer and use it in GitHub Desktop.
Fast and short way to get image size in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using(var img = Image.FromFile(file.Name)) | |
{ | |
var height = img.Height; | |
var width = img.Width; | |
} |
Huge performance improvement over the first option - thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had my doubts but that is really faster, it'll require less data (reads) from stream/file.
The big difference is from both parameters useEmbeddedColorManagement and validateImageData set to false.
Tested with a 195001 bytes JPEG, the original load Image.FromStream(fileStream) did read all the bytes from the stream and the Image.FromStream(fileStream, false, false) version did read only 4268 bytes (about 2,1%).