Creating a new bitmap out of the differences of two others 
Author Message
 Creating a new bitmap out of the differences of two others

Hi,

I am trying to find a way of comparing two bitmaps and creating a new
one containing just these differences. Going through pixel by pixel
works but is really really slow! I have been doing some surfing and
have come across a function called bitblt which seems to be abe to use
xor to do this, but I have not been able to get it working.

Am I on the right track? Does anybody have any other solutions?

Any help would be appreciated!

Thanks in advance,

AJB



Sat, 15 Oct 2005 04:25:21 GMT  
 Creating a new bitmap out of the differences of two others
Hi,

If you also use C#, we can use Bitmap.LockBits to get the pointer to the
bitmap data. Then, perform the operations on the memory directly. Please
check following article for more information:

Unsafe Image Processing
http://msdn.microsoft.com/library/en-us/dncscol/html/csharp11152001.asp

Besides that, we can also try the BitBlt Win32 API. Some samples are
available on the following web WinForm FAQ site:

http://www.syncfusion.com/faq/winforms/search/625.asp

Here is a code snippet that gets the difference of the bitmaps using XOR:

    Public Declare Function LoadImage Lib "user32" Alias "LoadImageA"
(ByVal hInst As Integer, ByVal lpsz As String, ByVal uType As Integer,
ByVal cxDesired As Integer, ByVal cyDesired As Integer, ByVal fuLoad As
Integer) As IntPtr
    Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal
hDestDC As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As
Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As
Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
    Public Declare Function DeleteObject Lib "gdi32" Alias "DeleteObject"
(ByVal hObject As IntPtr) As Integer
    Public Declare Function CreateCompatibleDC Lib "gdi32" Alias
"CreateCompatibleDC" (ByVal hdc As IntPtr) As IntPtr
    Public Declare Function CreateCompatibleBitmap Lib "gdi32" Alias
"CreateCompatibleBitmap" (ByVal hdc As IntPtr, ByVal nWidth As Integer,
ByVal nHeight As Integer) As IntPtr
    Public Declare Function SelectObject Lib "gdi32" Alias "SelectObject"
(ByVal hdc As IntPtr, ByVal hObject As IntPtr) As IntPtr
    Public Declare Function DeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal
hdc As IntPtr) As Integer

    Public Const SRCAND = &H8800C6
    Public Const SRCCOPY = &HCC0020
    Public Const SRCERASE = &H440328
    Public Const SRCINVERT = &H660046
    Public Const SRCPAINT = &HEE0086
    Public Const IMAGE_BITMAP = 0
    Public Const LR_LOADFROMFILE = &H10

        Dim hBmp1, hBmp2 As IntPtr
        Dim memDC1, memDC2, picDC As IntPtr
        Dim oldBmp1, oldBmp2 As IntPtr
        Dim picGraphics As Graphics
        Dim img As Image
        img = Image.FromFile("C:\1.bmp")

        hBmp1 = LoadImage(0, "c:\1.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE)
        hBmp2 = LoadImage(0, "c:\2.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE)
        memDC1 = CreateCompatibleDC(New IntPtr(0))
        memDC2 = CreateCompatibleDC(New IntPtr(0))
        oldBmp1 = SelectObject(memDC1, hBmp1)
        oldBmp2 = SelectObject(memDC2, hBmp2)

        BitBlt(memDC1, 0, 0, img.Width, img.Height, memDC2, 0, 0, SRCINVERT)
        picGraphics = PictureBox1.CreateGraphics

        picDC = picGraphics.GetHdc()
        BitBlt(picDC, 0, 0, img.Width, img.Height, memDC1, 0, 0, SRCPAINT)
        picGraphics.ReleaseHdc(picDC)

        oldBmp1 = SelectObject(memDC1, oldBmp1)
        oldBmp2 = SelectObject(memDC1, oldBmp2)

        DeleteDC(memDC1)
        DeleteDC(memDC2)
        DeleteObject(hBmp1)
        DeleteObject(hBmp2)

Best Regards,
Leo Chen

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

| Newsgroups: microsoft.public.dotnet.languages.vb
| Subject: Creating a new bitmap out of the differences of two others

| X-Newsreader: Forte Agent 1.91/32.564
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Lines: 15

| X-Abuse-Info: Please be sure to forward a copy of ALL headers
| X-Abuse-Info: Otherwise we will be unable to process your complaint
properly.
| NNTP-Posting-Date: Mon, 28 Apr 2003 16:12:46 EDT
| Date: Mon, 28 Apr 2003 21:25:21 +0100
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!c03.atl99!news.webusene
t.com!pc01.webusenet.com!fe04.atl2.webusenet.com.POSTED!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:104440
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Hi,
|
| I am trying to find a way of comparing two bitmaps and creating a new
| one containing just these differences. Going through pixel by pixel
| works but is really really slow! I have been doing some surfing and
| have come across a function called bitblt which seems to be abe to use
| xor to do this, but I have not been able to get it working.
|
| Am I on the right track? Does anybody have any other solutions?
|
| Any help would be appreciated!
|
| Thanks in advance,
|
| AJB
|
|



Sat, 15 Oct 2005 14:27:20 GMT  
 Creating a new bitmap out of the differences of two others
Thanks a lot for you help! Will give that a try!

:)


Quote:

>Hi,

>If you also use C#, we can use Bitmap.LockBits to get the pointer to the
>bitmap data. Then, perform the operations on the memory directly. Please
>check following article for more information:

>Unsafe Image Processing
>http://msdn.microsoft.com/library/en-us/dncscol/html/csharp11152001.asp

>Besides that, we can also try the BitBlt Win32 API. Some samples are
>available on the following web WinForm FAQ site:

>http://www.syncfusion.com/faq/winforms/search/625.asp

>Here is a code snippet that gets the difference of the bitmaps using XOR:

>    Public Declare Function LoadImage Lib "user32" Alias "LoadImageA"
>(ByVal hInst As Integer, ByVal lpsz As String, ByVal uType As Integer,
>ByVal cxDesired As Integer, ByVal cyDesired As Integer, ByVal fuLoad As
>Integer) As IntPtr
>    Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal
>hDestDC As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As
>Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As
>Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
>    Public Declare Function DeleteObject Lib "gdi32" Alias "DeleteObject"
>(ByVal hObject As IntPtr) As Integer
>    Public Declare Function CreateCompatibleDC Lib "gdi32" Alias
>"CreateCompatibleDC" (ByVal hdc As IntPtr) As IntPtr
>    Public Declare Function CreateCompatibleBitmap Lib "gdi32" Alias
>"CreateCompatibleBitmap" (ByVal hdc As IntPtr, ByVal nWidth As Integer,
>ByVal nHeight As Integer) As IntPtr
>    Public Declare Function SelectObject Lib "gdi32" Alias "SelectObject"
>(ByVal hdc As IntPtr, ByVal hObject As IntPtr) As IntPtr
>    Public Declare Function DeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal
>hdc As IntPtr) As Integer

>    Public Const SRCAND = &H8800C6
>    Public Const SRCCOPY = &HCC0020
>    Public Const SRCERASE = &H440328
>    Public Const SRCINVERT = &H660046
>    Public Const SRCPAINT = &HEE0086
>    Public Const IMAGE_BITMAP = 0
>    Public Const LR_LOADFROMFILE = &H10

>        Dim hBmp1, hBmp2 As IntPtr
>        Dim memDC1, memDC2, picDC As IntPtr
>        Dim oldBmp1, oldBmp2 As IntPtr
>        Dim picGraphics As Graphics
>        Dim img As Image
>        img = Image.FromFile("C:\1.bmp")

>        hBmp1 = LoadImage(0, "c:\1.bmp", IMAGE_BITMAP, 0, 0,
>LR_LOADFROMFILE)
>        hBmp2 = LoadImage(0, "c:\2.bmp", IMAGE_BITMAP, 0, 0,
>LR_LOADFROMFILE)
>        memDC1 = CreateCompatibleDC(New IntPtr(0))
>        memDC2 = CreateCompatibleDC(New IntPtr(0))
>        oldBmp1 = SelectObject(memDC1, hBmp1)
>        oldBmp2 = SelectObject(memDC2, hBmp2)

>        BitBlt(memDC1, 0, 0, img.Width, img.Height, memDC2, 0, 0, SRCINVERT)
>        picGraphics = PictureBox1.CreateGraphics

>        picDC = picGraphics.GetHdc()
>        BitBlt(picDC, 0, 0, img.Width, img.Height, memDC1, 0, 0, SRCPAINT)
>        picGraphics.ReleaseHdc(picDC)

>        oldBmp1 = SelectObject(memDC1, oldBmp1)
>        oldBmp2 = SelectObject(memDC1, oldBmp2)

>        DeleteDC(memDC1)
>        DeleteDC(memDC2)
>        DeleteObject(hBmp1)
>        DeleteObject(hBmp2)

>Best Regards,
>Leo Chen

>This posting is provided "AS IS" with no warranties, and confers no rights.

>--------------------

>| Newsgroups: microsoft.public.dotnet.languages.vb
>| Subject: Creating a new bitmap out of the differences of two others

>| X-Newsreader: Forte Agent 1.91/32.564
>| MIME-Version: 1.0
>| Content-Type: text/plain; charset=us-ascii
>| Content-Transfer-Encoding: 7bit
>| Lines: 15

>| X-Abuse-Info: Please be sure to forward a copy of ALL headers
>| X-Abuse-Info: Otherwise we will be unable to process your complaint
>properly.
>| NNTP-Posting-Date: Mon, 28 Apr 2003 16:12:46 EDT
>| Date: Mon, 28 Apr 2003 21:25:21 +0100
>| Path:
>cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
>e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!c03.atl99!news.webusene
>t.com!pc01.webusenet.com!fe04.atl2.webusenet.com.POSTED!not-for-mail
>| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:104440
>| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
>|
>| Hi,
>|
>| I am trying to find a way of comparing two bitmaps and creating a new
>| one containing just these differences. Going through pixel by pixel
>| works but is really really slow! I have been doing some surfing and
>| have come across a function called bitblt which seems to be abe to use
>| xor to do this, but I have not been able to get it working.
>|
>| Am I on the right track? Does anybody have any other solutions?
>|
>| Any help would be appreciated!
>|
>| Thanks in advance,
>|
>| AJB
>|
>|



Sat, 15 Oct 2005 18:15:33 GMT  
 Creating a new bitmap out of the differences of two others
I'm glad to help. :-)

Best Regards,
Leo Chen

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

| Newsgroups: microsoft.public.dotnet.languages.vb
| Subject: Re: Creating a new bitmap out of the differences of two others



| X-Newsreader: Forte Agent 1.91/32.564
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Lines: 131

| X-Abuse-Info: Please be sure to forward a copy of ALL headers
| X-Abuse-Info: Otherwise we will be unable to process your complaint
properly.
| NNTP-Posting-Date: Tue, 29 Apr 2003 06:03:02 EDT
| Date: Tue, 29 Apr 2003 11:15:33 +0100
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!c03.atl99!news.webusene
t.com!pc01.webusenet.com!fe10.atl2.webusenet.com.POSTED!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:104569
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Thanks a lot for you help! Will give that a try!
|
| :)
|

|
| >Hi,
| >
| >If you also use C#, we can use Bitmap.LockBits to get the pointer to the
| >bitmap data. Then, perform the operations on the memory directly. Please
| >check following article for more information:
| >
| >Unsafe Image Processing
| >http://msdn.microsoft.com/library/en-us/dncscol/html/csharp11152001.asp
| >
| >Besides that, we can also try the BitBlt Win32 API. Some samples are
| >available on the following web WinForm FAQ site:
| >
| >http://www.syncfusion.com/faq/winforms/search/625.asp
| >
| >Here is a code snippet that gets the difference of the bitmaps using XOR:
| >
| >    Public Declare Function LoadImage Lib "user32" Alias "LoadImageA"
| >(ByVal hInst As Integer, ByVal lpsz As String, ByVal uType As Integer,
| >ByVal cxDesired As Integer, ByVal cyDesired As Integer, ByVal fuLoad As
| >Integer) As IntPtr
| >    Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal
| >hDestDC As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth
As
| >Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As
| >Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
| >    Public Declare Function DeleteObject Lib "gdi32" Alias
"DeleteObject"
| >(ByVal hObject As IntPtr) As Integer
| >    Public Declare Function CreateCompatibleDC Lib "gdi32" Alias
| >"CreateCompatibleDC" (ByVal hdc As IntPtr) As IntPtr
| >    Public Declare Function CreateCompatibleBitmap Lib "gdi32" Alias
| >"CreateCompatibleBitmap" (ByVal hdc As IntPtr, ByVal nWidth As Integer,
| >ByVal nHeight As Integer) As IntPtr
| >    Public Declare Function SelectObject Lib "gdi32" Alias
"SelectObject"
| >(ByVal hdc As IntPtr, ByVal hObject As IntPtr) As IntPtr
| >    Public Declare Function DeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal
| >hdc As IntPtr) As Integer
| >
| >
| >    Public Const SRCAND = &H8800C6
| >    Public Const SRCCOPY = &HCC0020
| >    Public Const SRCERASE = &H440328
| >    Public Const SRCINVERT = &H660046
| >    Public Const SRCPAINT = &HEE0086
| >    Public Const IMAGE_BITMAP = 0
| >    Public Const LR_LOADFROMFILE = &H10
| >
| >        Dim hBmp1, hBmp2 As IntPtr
| >        Dim memDC1, memDC2, picDC As IntPtr
| >        Dim oldBmp1, oldBmp2 As IntPtr
| >        Dim picGraphics As Graphics
| >        Dim img As Image
| >        img = Image.FromFile("C:\1.bmp")
| >
| >        hBmp1 = LoadImage(0, "c:\1.bmp", IMAGE_BITMAP, 0, 0,
| >LR_LOADFROMFILE)
| >        hBmp2 = LoadImage(0, "c:\2.bmp", IMAGE_BITMAP, 0, 0,
| >LR_LOADFROMFILE)
| >        memDC1 = CreateCompatibleDC(New IntPtr(0))
| >        memDC2 = CreateCompatibleDC(New IntPtr(0))
| >        oldBmp1 = SelectObject(memDC1, hBmp1)
| >        oldBmp2 = SelectObject(memDC2, hBmp2)
| >
| >        BitBlt(memDC1, 0, 0, img.Width, img.Height, memDC2, 0, 0,
SRCINVERT)
| >        picGraphics = PictureBox1.CreateGraphics
| >
| >        picDC = picGraphics.GetHdc()
| >        BitBlt(picDC, 0, 0, img.Width, img.Height, memDC1, 0, 0,
SRCPAINT)
| >        picGraphics.ReleaseHdc(picDC)
| >
| >        oldBmp1 = SelectObject(memDC1, oldBmp1)
| >        oldBmp2 = SelectObject(memDC1, oldBmp2)
| >
| >        DeleteDC(memDC1)
| >        DeleteDC(memDC2)
| >        DeleteObject(hBmp1)
| >        DeleteObject(hBmp2)
| >
| >Best Regards,
| >Leo Chen
| >
| >This posting is provided "AS IS" with no warranties, and confers no
rights.
| >
| >
| >
| >--------------------

| >| Newsgroups: microsoft.public.dotnet.languages.vb
| >| Subject: Creating a new bitmap out of the differences of two others

| >| X-Newsreader: Forte Agent 1.91/32.564
| >| MIME-Version: 1.0
| >| Content-Type: text/plain; charset=us-ascii
| >| Content-Transfer-Encoding: 7bit
| >| Lines: 15

| >| X-Abuse-Info: Please be sure to forward a copy of ALL headers
| >| X-Abuse-Info: Otherwise we will be unable to process your complaint
| >properly.
| >| NNTP-Posting-Date: Mon, 28 Apr 2003 16:12:46 EDT
| >| Date: Mon, 28 Apr 2003 21:25:21 +0100
| >| Path:
|

Quote:
>cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onli

n
|
Quote:
>e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!c03.atl99!news.webusen

e
| >t.com!pc01.webusenet.com!fe04.atl2.webusenet.com.POSTED!not-for-mail
| >| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:104440
| >| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| >|
| >| Hi,
| >|
| >| I am trying to find a way of comparing two bitmaps and creating a new
| >| one containing just these differences. Going through pixel by pixel
| >| works but is really really slow! I have been doing some surfing and
| >| have come across a function called bitblt which seems to be abe to use
| >| xor to do this, but I have not been able to get it working.
| >|
| >| Am I on the right track? Does anybody have any other solutions?
| >|
| >| Any help would be appreciated!
| >|
| >| Thanks in advance,
| >|
| >| AJB
| >|
| >|
|
|
|


Sun, 16 Oct 2005 10:31:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Any Differences in creating new object via CreateObject or via New

2. How to calculate the difference between two dates (time elapsed between two program starts)

3. Problem: Two forms swap each others taskbar buttons

4. Reading bitmap files into memory and creating bitmap

5. New VB Samples, Internet Client/Server, DirectX, Others

6. New VB Samples (Client/Server, Internet , DirectX, Others)

7. PROBLEM: getting a new control in front of others during runtime

8. New VB Samples (Client/Server, Internet , DirectX, Others)

9. New VB Samples, Internet Client/Server, DirectX, Others

10. New VB Samples, Internet Client/Server, DirectX, Others

11. New VB Samples (Client/Server, Internet , DirectX, Others)

12. difference between two dates ,in years,months,and days

 

 
Powered by phpBB® Forum Software