Solved

fastest way to compare 2 bitmaps

Posted on 2007-11-21
4
1,624 Views
Last Modified: 2008-02-01
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...
0
Comment
Question by:Ruttensoft
  • 2
4 Comments
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20331955
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

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20331969
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
0
 
LVL 18

Accepted Solution

by:
armoghan earned 500 total points
ID: 20333488
0
 
LVL 18

Expert Comment

by:armoghan
ID: 20333506
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now