Link to home
Start Free TrialLog in
Avatar of Ruttensoft
Ruttensoft

asked on

fastest way to compare 2 bitmaps

Hello

What's the fastest way to compare 2 bitmaps?
Comparing with GetPixel is veeeeery slow...

I just want to know if bitmap a is the same as b or not...
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

You can use the LockBits and UnlockBits methods to get the image data from a bitmap:
Get data:
 
Dim bounds As New Rectangle(0, 0, bitmap.Width, bitmap.Height)
bitmapData = bitmap.LockBits(bounds, ImageLockMode.Read, PixelFormat.Format32bppRgb)
 
Dim size As Integer = bitmapData.Stride * bitmapData.Height
Dim imageBytes As new Byte(size)
Marshal.Copy(bitmapData.Scan0, imageBytes, 0, size)
bitmap.UnlockBits(bitmapData)

Open in new window

The fastest way is to compare internal bitmap structure, by taking the HBITMAP handle of each.
It is extremely complex, have a look to the C++ code:
http://www.codeproject.com/useritems/BitmapCompare.asp
ASKER CERTIFIED SOLUTION
Avatar of armoghan
armoghan
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Another interesting debate is present here from
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1057994&SiteID=1

If important thing is not the pixels to be equals, just human readable eye difference, then jo0ls
has given good argument