Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. full code for comparing bitmaps

full code for comparing bitmaps

Scheduled Pinned Locked Moved C / C++ / MFC
19 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CPalliniC CPallini

    if (bitmap1 == bitmap2)

    BTW Don't forget to visit www.cpallini.freeproductz.com for more free 'full code'. :-D

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    M Offline
    M Offline
    Michael Schubert
    wrote on last edited by
    #9

    Ingenious. ;)

    1 Reply Last reply
    0
    • K kaushal kishore sharma

      pallini..thnx..but i need a full running code for comparing 2 bitmaps.. i have posted my code but i cant understand what is wrong in my code... can you help please.. 1. void CPixelView::OnDraw(CDC* pDC) { CPixelDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here { COLORREF color[255][255],color1[255][255]; CBitmap bitmap,bitmap1; CString file1,file2,strText; file1.Format("C:\\1.bmp"); file2.Format("C:\\3.bmp"); CDC dcMemory,dcMemory1; int r[255][255],R[255][255]; // 1st image HBITMAP hBitmap1 = (HBITMAP)::LoadImage(NULL,file1,IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE );//| LR_CREATEDIBSECTION); //2nd image HBITMAP hBitmap2 = (HBITMAP)::LoadImage(NULL,file2,IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE ); // Attach the loaded image to the CBitmap object. bitmap.Attach(hBitmap1); bitmap1.Attach(hBitmap2); dcMemory.CreateCompatibleDC(pDC); dcMemory.SelectObject(&bitmap); dcMemory1.CreateCompatibleDC(pDC); dcMemory1.SelectObject(&bitmap1); pDC->BitBlt(0,0,200,200,&dcMemory,0,0,SRCCOPY); pDC->BitBlt(0,0,300,700,&dcMemory1,0,0,SRCCOPY); //for all the pixels for(int i=0;i<48;i++) { for(int j=0;j<48;j++) { HDC hDC = ::GetDC(this->GetSafeHwnd()); color[i][j] = ::GetPixel(hDC,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC); r[i][j]=GetRValue(color[i][j]); HDC hDC1 = ::GetDC(this->GetSafeHwnd()); color1[i][j] = ::GetPixel(hDC1,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC1); R[i][j]=GetRValue(color1[i][j]); } }//got the pixel values } }

      M Offline
      M Offline
      Michael Schubert
      wrote on last edited by
      #10

      kaushal kishore sharma wrote:

      allini..thnx..but i need a full running code for comparing 2 bitmaps

      He just posted the code.

      1 Reply Last reply
      0
      • R Rajesh R Subramanian

        Read the guidelines[^] before you make another post. For once, what is pissing me off is your TXSTPK. Stop using SMS language here. Hundreds of people read it every day. So, act like a professional.

        Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

        M Offline
        M Offline
        Michael Schubert
        wrote on last edited by
        #11

        Rajesh R Subramanian wrote:

        For once, what is pissing me off is your TXSTPK

        You forgot the ASAP and URGENTZZ

        1 Reply Last reply
        0
        • K kaushal kishore sharma

          pallini..thnx..but i need a full running code for comparing 2 bitmaps.. i have posted my code but i cant understand what is wrong in my code... can you help please.. 1. void CPixelView::OnDraw(CDC* pDC) { CPixelDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here { COLORREF color[255][255],color1[255][255]; CBitmap bitmap,bitmap1; CString file1,file2,strText; file1.Format("C:\\1.bmp"); file2.Format("C:\\3.bmp"); CDC dcMemory,dcMemory1; int r[255][255],R[255][255]; // 1st image HBITMAP hBitmap1 = (HBITMAP)::LoadImage(NULL,file1,IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE );//| LR_CREATEDIBSECTION); //2nd image HBITMAP hBitmap2 = (HBITMAP)::LoadImage(NULL,file2,IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE ); // Attach the loaded image to the CBitmap object. bitmap.Attach(hBitmap1); bitmap1.Attach(hBitmap2); dcMemory.CreateCompatibleDC(pDC); dcMemory.SelectObject(&bitmap); dcMemory1.CreateCompatibleDC(pDC); dcMemory1.SelectObject(&bitmap1); pDC->BitBlt(0,0,200,200,&dcMemory,0,0,SRCCOPY); pDC->BitBlt(0,0,300,700,&dcMemory1,0,0,SRCCOPY); //for all the pixels for(int i=0;i<48;i++) { for(int j=0;j<48;j++) { HDC hDC = ::GetDC(this->GetSafeHwnd()); color[i][j] = ::GetPixel(hDC,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC); r[i][j]=GetRValue(color[i][j]); HDC hDC1 = ::GetDC(this->GetSafeHwnd()); color1[i][j] = ::GetPixel(hDC1,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC1); R[i][j]=GetRValue(color1[i][j]); } }//got the pixel values } }

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #12

          Well, you're "getting there"; Me thing you do not need to keep arrays of COLORREF or the r and R arrays You should be able to get the size of the bitmaps dynamically (because a bitmap of 48 pixel is really small) No need to get the DC twice. Now that you have the color for the same pixel position in both bitmaps; what should you be doing with them ? compare them ? maybe ?

          This signature was proudly tested on animals.

          K 1 Reply Last reply
          0
          • K kaushal kishore sharma

            can anyone send me full code for comparing two bitmaps... thank you..

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #13

            how many times do you need to post this same question?

            1 Reply Last reply
            0
            • CPalliniC CPallini

              if (bitmap1 == bitmap2)

              BTW Don't forget to visit www.cpallini.freeproductz.com for more free 'full code'. :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #14

              :laugh: And can we use of this code for other formats like jpg? :laugh:

              CPalliniC 1 Reply Last reply
              0
              • K kaushal kishore sharma

                can anyone send me full code for comparing two bitmaps... thank you..

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #15

                Of course you can use of CImage class for read your bitmap files and like your code you can use of two loop(See CImage::GetPixel) I think its easy than your code.

                1 Reply Last reply
                0
                • M Maximilien

                  Well, you're "getting there"; Me thing you do not need to keep arrays of COLORREF or the r and R arrays You should be able to get the size of the bitmaps dynamically (because a bitmap of 48 pixel is really small) No need to get the DC twice. Now that you have the color for the same pixel position in both bitmaps; what should you be doing with them ? compare them ? maybe ?

                  This signature was proudly tested on animals.

                  K Offline
                  K Offline
                  kaushal kishore sharma
                  wrote on last edited by
                  #16

                  thank you for the reply. can you tell how to make changes in the code. I am studying VC++ so not too much knowledge about the language.So can you help me with the code. Yes i am comparing both bitmap for checking whether both images are same or different. Thank You kaushal kishore Sharma kaushal..

                  1 Reply Last reply
                  0
                  • K kaushal kishore sharma

                    can anyone send me full code for comparing two bitmaps... thank you..

                    PJ ArendsP Offline
                    PJ ArendsP Offline
                    PJ Arends
                    wrote on last edited by
                    #17

                    http://www.codeproject.com/KB/graphics/BitmapCompare.aspx[^] And also http://www.codeproject.com/script/Forums/View.aspx?fid=368891&msg=1957223[^]

                    Within you lies the power for good; Use it!

                    1 Reply Last reply
                    0
                    • H Hamid Taebi

                      :laugh: And can we use of this code for other formats like jpg? :laugh:

                      CPalliniC Offline
                      CPalliniC Offline
                      CPallini
                      wrote on last edited by
                      #18

                      Hamid. wrote:

                      And can we use of this code for other formats like jpg?

                      Nope. You have to change it:

                      if ( jpegImage1 == jpegImage2) ...

                      Details for all image formats on www.cpallini.freeproductz.com. :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      In testa che avete, signor di Ceprano?

                      H 1 Reply Last reply
                      0
                      • CPalliniC CPallini

                        Hamid. wrote:

                        And can we use of this code for other formats like jpg?

                        Nope. You have to change it:

                        if ( jpegImage1 == jpegImage2) ...

                        Details for all image formats on www.cpallini.freeproductz.com. :)

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                        [My articles]

                        H Offline
                        H Offline
                        Hamid Taebi
                        wrote on last edited by
                        #19

                        I decided to made a supplement for your magic site. :-D

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups