Solved

Compare Bitmaps and get XY coordinates

Posted on 2001-08-29
4
492 Views
Last Modified: 2008-02-01
Greetings!

I wish to compare two bitmaps of the same size/depth/etc and create a list of xy coordinates that are different between the two.

Thanks in advance.
0
Comment
Question by:bhh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
Ark earned 100 total points
ID: 6438986
Hi
'API way is faster then native VB.

Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Dim sList() As String
Private Function CreateList() As Long
   Dim x As Integer, y As Integer
   Dim clr1 As Long,clr2 As Long
   Dim nCount As Long
   Redim sList(0)
   sList(0) = "Pictures are different at:"
   Picture1.ScaleMode = vbPixels
   Picture2.ScaleMode = vbPixels
   For x = 1 To Picture1.ScaleWidth
       For y = 1 To Picture1.ScaleHeight
           clr1 = GetPixel(Picture1.hdc,x,y)
           clr2 = GetPixel(Picture2.hdc,x,y)
           If clr2 <> clr1 Then
              nCount = nCount + 1
              Redim Preserve sList(nCount)
              sList(nCount) = "X = " & x & "; Y = " & Y
           End If
       Next y
   Next x
End Function

Cheers
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 6439179
If this is only for very small bitmaps read no further. But if you are to compare large bitmaps you might want to read about DIB's (Device Independant Bitmaps) which allows you to access a bitmap's actual pixels directly. This would allow you to compare two bitmaps by just comparing a byte array with another byte array, which is *much* faster than the GetPixel solution. To learn about DIB's and download free source code showing you how to use 'em go to the "Media" section at...

  http://www.vbaccelerator.com

...and download the cDIBSection.cls file.
0
 
LVL 2

Author Comment

by:bhh
ID: 6440319
I'll try both and get back to you.  Give me a couple of days to play with it.  Thanks!
0
 
LVL 2

Author Comment

by:bhh
ID: 6448214
This was a tough one.  I decided to go with Ark's answer simply because it exactly matched my question and need.

VBMaster - your suggestion opened up new worlds - thanks. Go here: http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20177332

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

732 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