How do I reliably get an image dimensions in .NET without loading the image?

后端 未结 5 2003
猫巷女王i
猫巷女王i 2020-12-01 16:04

I know how to get the size (x,y) of an image

Image.FromFile(\"cat.jpg\").Size

BUT that requires loading the image from memory.

When

5条回答
  •  攒了一身酷
    2020-12-01 16:32

    Doing this usually involves actually opening the file and reading only its header (the first few bytes) to find its format and the size. You don't need to read the whole file to find out it's size. Sometimes the size is even in a specific offset in the file so finding the size is only reading 8 bytes.

    You can use filemon.exe to actually find out what windows explorer itself does to find the size.

提交回复
热议问题