Pergunta

I'm using .net framework 4.0, System.Drawing.Image.FromFile to read in the bitmap and jpeg format images.

using (Image img = Image.FromFile("image file path")) { }

I put a stopwatch just to track the time taken, and it show me the result that take in bitmap is faster than jpeg images??

same image but different format and size. example result as below:
image1.bmp (~4938 KB) - time taken ~5 ms. (faster)
image1.jpg (~545 KB)- time taken ~54 ms. (slower)

My question is:
1. Is it possible that the method read in the bitmap (big size) can faster than jpeg (small size)? Why?
2. Could someone please help to explain the logic happen in "Image.FromFile()" method for different file format?

i search the msdn and web, but cannot find the performance details related to the file format.
http://msdn.microsoft.com/en-us/library/4sahykhd%28v=vs.100%29.aspx

thanks.

Foi útil?

Solução

Likely explanation:

  • there is no difference in disk IO because you are actually reading files from cache - so file size does not matter much.
  • jpg is compressed format so it need to be decompressed to be represented as editable image. BMP is essentially one-to-one mapping between memory and disk format - no significant processing needed on load.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top