Questions about Bitmap class

  • Thread starter Thread starter Danny Ni
  • Start date Start date
D

Danny Ni

Hi,

I have a couple of questions about System.Drawing.Bitmap class:
(1) Can I tell the size (as in how many KB/MB it will take to store, not
width and height) without storing it into hard drive?
(2) Is there a way to compare 2 bitmaps? Say I download 2 jpg files from 2
different sites, I want to know if they are the same. If there is no way to
compare, will method in (1) work?

TIA
 
I have a couple of questions about System.Drawing.Bitmap class:
(1) Can I tell the size (as in how many KB/MB it will take to store, not
width and height)  without storing it into hard drive?

You can save it to a MemoryStream first, and then check how large that
ends up. This way you account for compression etc.
(2) Is there a way to compare 2 bitmaps? Say I download 2 jpg files from 2
different sites, I want to know if they are the same.

You have to do that pixel-by-pixel. A slow way to do so is to use
GetPixel. A fast way is to use LockBits to get raw pointers, and then
scan through in a fast loop (preferably comparing word-sized chunks
rather than pixels).
 
Back
Top