Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Compare Bitmaps and get XY coordinates

Posted on 2001-08-29
Medium Priority
501 Views
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.

0
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
• 2

LVL 28

Accepted Solution

Ark earned 400 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

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

0

LVL 2

Author Comment

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

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

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
###### Suggested Courses
Course of the Month9 days, 5 hours left to enroll