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. Showing an image to the use

Showing an image to the use

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++graphicsdebugging
10 Posts 3 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.
  • L Offline
    L Offline
    llp00na
    wrote on last edited by
    #1

    Hi guys, I have got an urgent question which I need to solve, Plzzz this is very urgent, my whole dissertation depends on it, can you provide guidance? Deadline is Thursday afternoon. I have created an MFC application (dialog-based), added a Picture control to the dialog in order show images (.bmp) to the user. Now I am trying to display the images which the user selects in a scrollable area(for which i added a CScrollView). The application works fine when I capture screenshots manually using printSc and paste them in Paint, however I want the system to automatically capture screenshots and display them. The system indeed saves the image into the hard drive but fails to show to the user. I am getting Debug Assertion Failed! // This method captures a screen shot of the current page void CDetectChangeDlg::CaptureInstantPage() { RECT rc; HWND hWnd = m_webBrowser.GetSafeHwnd(); ::GetWindowRect (hWnd,&rc); HDC hDC = ::GetDC(0); HDC memDC = ::CreateCompatibleDC ( hDC ); HBITMAP memBM = ::CreateCompatibleBitmap ( hDC, rc.right-rc.left-20, rc.bottom-rc.top ); ::SelectObject ( memDC, memBM ); ::BitBlt( memDC, 0, 0, rc.right-rc.left-20, rc.bottom-rc.top, hDC, rc.left, rc.top , SRCCOPY ); char* imageName = (char*)"InstantImage.bmp"; // A screen shot of the current page AnotherWayToSaveBitmap(imageName, memBM); //SaveBitmap(imageName, memBM); // This way does not work ::DeleteObject(memBM); ::DeleteObject(memDC); ::ReleaseDC( 0, hDC ); } void CDetectChangeDlg:: AnotherWayToSaveBitmap(char *name,HBITMAP hBitMap) { CBitmap bmp; bmp.Attach(hBitMap); BITMAP bitmap; bmp.GetBitmap(&bitmap); int size = bitmap.bmWidth*bitmap.bmHeight*bitmap.bmBitsPixel/8; BYTE *lpBits = new BYTE[size]; ::GetBitmapBits(hBitMap,size,lpBits); WriteBmp(name,&bitmap,(int*)lpBits); delete []lpBits; } // Show the image to the user void ManualImageSegmenterDlg::DisplayImage(CString strFileName) { imageScrollView->m_Bitmap.DeleteObject(); HBITMAP hBmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(), strFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); imageScrollView->m_Bitmap.Attach(hBmp); BITMAP bm; imageScrollView->m_Bitmap.GetBitmap(&bm); imageScrollView->m_sizeBmp = CSize(bm.bmWidth, bm.bmHeight); imageScrollView->SetScrollSizes(MM_TEXT, imageScrollView->m_sizeBmp); imageScrollView->Invalidate(); }

    llp00na

    CPalliniC 1 Reply Last reply
    0
    • L llp00na

      Hi guys, I have got an urgent question which I need to solve, Plzzz this is very urgent, my whole dissertation depends on it, can you provide guidance? Deadline is Thursday afternoon. I have created an MFC application (dialog-based), added a Picture control to the dialog in order show images (.bmp) to the user. Now I am trying to display the images which the user selects in a scrollable area(for which i added a CScrollView). The application works fine when I capture screenshots manually using printSc and paste them in Paint, however I want the system to automatically capture screenshots and display them. The system indeed saves the image into the hard drive but fails to show to the user. I am getting Debug Assertion Failed! // This method captures a screen shot of the current page void CDetectChangeDlg::CaptureInstantPage() { RECT rc; HWND hWnd = m_webBrowser.GetSafeHwnd(); ::GetWindowRect (hWnd,&rc); HDC hDC = ::GetDC(0); HDC memDC = ::CreateCompatibleDC ( hDC ); HBITMAP memBM = ::CreateCompatibleBitmap ( hDC, rc.right-rc.left-20, rc.bottom-rc.top ); ::SelectObject ( memDC, memBM ); ::BitBlt( memDC, 0, 0, rc.right-rc.left-20, rc.bottom-rc.top, hDC, rc.left, rc.top , SRCCOPY ); char* imageName = (char*)"InstantImage.bmp"; // A screen shot of the current page AnotherWayToSaveBitmap(imageName, memBM); //SaveBitmap(imageName, memBM); // This way does not work ::DeleteObject(memBM); ::DeleteObject(memDC); ::ReleaseDC( 0, hDC ); } void CDetectChangeDlg:: AnotherWayToSaveBitmap(char *name,HBITMAP hBitMap) { CBitmap bmp; bmp.Attach(hBitMap); BITMAP bitmap; bmp.GetBitmap(&bitmap); int size = bitmap.bmWidth*bitmap.bmHeight*bitmap.bmBitsPixel/8; BYTE *lpBits = new BYTE[size]; ::GetBitmapBits(hBitMap,size,lpBits); WriteBmp(name,&bitmap,(int*)lpBits); delete []lpBits; } // Show the image to the user void ManualImageSegmenterDlg::DisplayImage(CString strFileName) { imageScrollView->m_Bitmap.DeleteObject(); HBITMAP hBmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(), strFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); imageScrollView->m_Bitmap.Attach(hBmp); BITMAP bm; imageScrollView->m_Bitmap.GetBitmap(&bm); imageScrollView->m_sizeBmp = CSize(bm.bmWidth, bm.bmHeight); imageScrollView->SetScrollSizes(MM_TEXT, imageScrollView->m_sizeBmp); imageScrollView->Invalidate(); }

      llp00na

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

      llp00na wrote:

      Plzzz this is very urgent

      You know that makes your question becoming a low-low-low priority one... :rolleyes:

      llp00na wrote:

      I am getting Debug Assertion Failed!

      What is the asserting line? Did you give a look at the stack calls window? :)

      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?

      L 1 Reply Last reply
      0
      • CPalliniC CPallini

        llp00na wrote:

        Plzzz this is very urgent

        You know that makes your question becoming a low-low-low priority one... :rolleyes:

        llp00na wrote:

        I am getting Debug Assertion Failed!

        What is the asserting line? Did you give a look at the stack calls window? :)

        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]

        L Offline
        L Offline
        llp00na
        wrote on last edited by
        #3

        I am really deseparate, my future depends on that Assertion line is: imageScrollView->m_sizeBmp = CSize(bm.bmWidth, bm.bmHeight); This also happens if I try to show jpgs and other formats. It could be something to do with the format of the image and the CScrollView. No I did not, It's been a while since I programmed. So i dont know how to use the stack calls window

        llp00na

        CPalliniC 1 Reply Last reply
        0
        • L llp00na

          I am really deseparate, my future depends on that Assertion line is: imageScrollView->m_sizeBmp = CSize(bm.bmWidth, bm.bmHeight); This also happens if I try to show jpgs and other formats. It could be something to do with the format of the image and the CScrollView. No I did not, It's been a while since I programmed. So i dont know how to use the stack calls window

          llp00na

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

          llp00na wrote:

          I am really deseparate, my future depends on that

          Sorry about...

          llp00na wrote:

          Assertion line is: imageScrollView->m_sizeBmp = CSize(bm.bmWidth, bm.bmHeight);

          What is exactly the assertion message? :)

          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?

          L B 2 Replies Last reply
          0
          • CPalliniC CPallini

            llp00na wrote:

            I am really deseparate, my future depends on that

            Sorry about...

            llp00na wrote:

            Assertion line is: imageScrollView->m_sizeBmp = CSize(bm.bmWidth, bm.bmHeight);

            What is exactly the assertion message? :)

            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]

            L Offline
            L Offline
            llp00na
            wrote on last edited by
            #5

            it is debug assertion failed Program: ....\DetectChange.exe File:.......\include\afxwin1.inl Line: 221 For more info (Press retry to debug) So i pressed retry and got: Unhandled exception at mfc71d.dll in DetectChange.exe: User breakpoint

            llp00na

            1 Reply Last reply
            0
            • CPalliniC CPallini

              llp00na wrote:

              I am really deseparate, my future depends on that

              Sorry about...

              llp00na wrote:

              Assertion line is: imageScrollView->m_sizeBmp = CSize(bm.bmWidth, bm.bmHeight);

              What is exactly the assertion message? :)

              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]

              B Offline
              B Offline
              bulg
              wrote on last edited by
              #6

              The api that you're using to load the bitmap returns 0 if it failed to load. why don't you do some error checking??? (if statements) if you're averse to that, then step through it (insert a breakpoint before you load, then run it, then press f10 and f11 to step through or step into lines, typing in variable names in the QuickWatch window to see what values are what).

              L CPalliniC 2 Replies Last reply
              0
              • B bulg

                The api that you're using to load the bitmap returns 0 if it failed to load. why don't you do some error checking??? (if statements) if you're averse to that, then step through it (insert a breakpoint before you load, then run it, then press f10 and f11 to step through or step into lines, typing in variable names in the QuickWatch window to see what values are what).

                L Offline
                L Offline
                llp00na
                wrote on last edited by
                #7

                I tried if (hBmp != 0){ } I still got the same error message ANy more ideas

                llp00na

                1 Reply Last reply
                0
                • B bulg

                  The api that you're using to load the bitmap returns 0 if it failed to load. why don't you do some error checking??? (if statements) if you're averse to that, then step through it (insert a breakpoint before you load, then run it, then press f10 and f11 to step through or step into lines, typing in variable names in the QuickWatch window to see what values are what).

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

                  It's OK. It would be even better if you reply to the right post. :-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]

                  In testa che avete, signor di Ceprano?

                  B L 2 Replies Last reply
                  0
                  • CPalliniC CPallini

                    It's OK. It would be even better if you reply to the right post. :-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]

                    B Offline
                    B Offline
                    bulg
                    wrote on last edited by
                    #9

                    my bad, did it send you an email?

                    1 Reply Last reply
                    0
                    • CPalliniC CPallini

                      It's OK. It would be even better if you reply to the right post. :-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]

                      L Offline
                      L Offline
                      llp00na
                      wrote on last edited by
                      #10

                      Can you send you the code to inspect please ???

                      llp00na

                      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