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. Comparing bitmap problem

Comparing bitmap problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++graphicsquestion
7 Posts 4 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.
  • K Offline
    K Offline
    kaushal kishore sharma
    wrote on last edited by
    #1

    I am using this code for comparing bitmaps. it is compiling without error but when we execute it just a blank window arrives with a error message and ask to close the program. Can anyone see what is the solution for this code. 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]; HBITMAP hBitmap1 = (HBITMAP)::LoadImage(NULL,file1,IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE );//| LR_CREATEDIBSECTION); 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); dcMemory1.CreateCompatibleDC(pDC); dcMemory.SelectObject(&bitmap); dcMemory1.SelectObject(&bitmap1); pDC->BitBlt(0,0,200,200,&dcMemory,0,0,SRCCOPY); pDC->BitBlt(300,300,700,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()); HDC hDC1 = ::GetDC(this->GetSafeHwnd()); color[i][j] = ::GetPixel(hDC,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC); r[i][j]=GetRValue(color[i][j]); color1[i][j] = ::GetPixel(hDC1,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC1); R[i][j]=GetRValue(color1[i][j]); } }//got the pixel values } } Thank You kaushal kishore sharma

    L H M 3 Replies Last reply
    0
    • K kaushal kishore sharma

      I am using this code for comparing bitmaps. it is compiling without error but when we execute it just a blank window arrives with a error message and ask to close the program. Can anyone see what is the solution for this code. 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]; HBITMAP hBitmap1 = (HBITMAP)::LoadImage(NULL,file1,IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE );//| LR_CREATEDIBSECTION); 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); dcMemory1.CreateCompatibleDC(pDC); dcMemory.SelectObject(&bitmap); dcMemory1.SelectObject(&bitmap1); pDC->BitBlt(0,0,200,200,&dcMemory,0,0,SRCCOPY); pDC->BitBlt(300,300,700,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()); HDC hDC1 = ::GetDC(this->GetSafeHwnd()); color[i][j] = ::GetPixel(hDC,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC); r[i][j]=GetRValue(color[i][j]); color1[i][j] = ::GetPixel(hDC1,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC1); R[i][j]=GetRValue(color1[i][j]); } }//got the pixel values } } Thank You kaushal kishore sharma

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      kaushal kishore sharma wrote:

      it is compiling without error

      Compilers don't catch errors like say, null pointer errors. Try debugging your code to find the problem.

      led mike

      K 1 Reply Last reply
      0
      • K kaushal kishore sharma

        I am using this code for comparing bitmaps. it is compiling without error but when we execute it just a blank window arrives with a error message and ask to close the program. Can anyone see what is the solution for this code. 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]; HBITMAP hBitmap1 = (HBITMAP)::LoadImage(NULL,file1,IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE );//| LR_CREATEDIBSECTION); 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); dcMemory1.CreateCompatibleDC(pDC); dcMemory.SelectObject(&bitmap); dcMemory1.SelectObject(&bitmap1); pDC->BitBlt(0,0,200,200,&dcMemory,0,0,SRCCOPY); pDC->BitBlt(300,300,700,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()); HDC hDC1 = ::GetDC(this->GetSafeHwnd()); color[i][j] = ::GetPixel(hDC,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC); r[i][j]=GetRValue(color[i][j]); color1[i][j] = ::GetPixel(hDC1,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC1); R[i][j]=GetRValue(color1[i][j]); } }//got the pixel values } } Thank You kaushal kishore sharma

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

        Same question again!

        1 Reply Last reply
        0
        • L led mike

          kaushal kishore sharma wrote:

          it is compiling without error

          Compilers don't catch errors like say, null pointer errors. Try debugging your code to find the problem.

          led mike

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

          thank you led mike. i have done debugging of the program it is giving stack overflows dialog. so you can check the code where it is giving me this error. My main moto is to compare bitmaps if you have any code related to this field do help me. I will be very thankful to you. Thank You kaushal kishore sharma

          1 Reply Last reply
          0
          • K kaushal kishore sharma

            I am using this code for comparing bitmaps. it is compiling without error but when we execute it just a blank window arrives with a error message and ask to close the program. Can anyone see what is the solution for this code. 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]; HBITMAP hBitmap1 = (HBITMAP)::LoadImage(NULL,file1,IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE );//| LR_CREATEDIBSECTION); 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); dcMemory1.CreateCompatibleDC(pDC); dcMemory.SelectObject(&bitmap); dcMemory1.SelectObject(&bitmap1); pDC->BitBlt(0,0,200,200,&dcMemory,0,0,SRCCOPY); pDC->BitBlt(300,300,700,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()); HDC hDC1 = ::GetDC(this->GetSafeHwnd()); color[i][j] = ::GetPixel(hDC,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC); r[i][j]=GetRValue(color[i][j]); color1[i][j] = ::GetPixel(hDC1,i,j); ::ReleaseDC(this->GetSafeHwnd(), hDC1); R[i][j]=GetRValue(color1[i][j]); } }//got the pixel values } } Thank You kaushal kishore sharma

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Why are you selecting bitmaps into memory DCs, but then getting window DCs to get pixel values from? Where is the error occurring?

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            K 1 Reply Last reply
            0
            • M Mark Salsbery

              Why are you selecting bitmaps into memory DCs, but then getting window DCs to get pixel values from? Where is the error occurring?

              Mark Salsbery Microsoft MVP - Visual C++ :java:

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

              thank you sir. i am doing my selecting bitmap work using memorydc since beginning. i do not myself, where is the problem. It is executing but giving blank window and a dialog box written "pixel MFC Application has encountered a problem and needs to close. We are sorry for the inconvenience." and after this i click on debug then it is giving "Stack overflow" so please help me. Thank You kaushal kishore sharma

              M 1 Reply Last reply
              0
              • K kaushal kishore sharma

                thank you sir. i am doing my selecting bitmap work using memorydc since beginning. i do not myself, where is the problem. It is executing but giving blank window and a dialog box written "pixel MFC Application has encountered a problem and needs to close. We are sorry for the inconvenience." and after this i click on debug then it is giving "Stack overflow" so please help me. Thank You kaushal kishore sharma

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                kaushal kishore sharma wrote:

                i do not myself, where is the problem.

                Then how do you know the problem is in the code you posted? Like others have mentioned, you need to debug this. Put a breakpoint at the start of your posted code and step through line by line. Are the LoadImage() calls succeeding? Are the SelectObject calls succeeding? Are any calls succeeding? :) Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                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