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