我正在使用下面的功能来实时处理图像。该函数使用计时器每10秒调用一次。
问题是,我得到了一个断言失败,并没有找到确切的问题。我尝试了CImage::ReleaseDC()和DeleteDC()作为ImageDC,但没有成功。
有什么想法吗?
LRESULT CAutodetectDialog::AutoscanPatterns(WPARAM, LPARAM)
{
HWND hwnd = ::FindWindow(NULL, windowTitle);
if (hwnd != NULL)
for (int i=0; i<N_NUMBERS; i++)
{
CImage image;
image.Create(dbParams.width, dbParams.height, 24);
CImageDC imageDC(image);
::SetWindowOrgEx(imageDC, db.topLeft.x, dbParams.topLeft.y + i * dbParams.height, NULL);
::PrintWindow(hwnd, imageDC, PW_CLIENTONLY);
// Process the image - processing takes < 1 sec
// and the image parameter is not being changed
SaveImagePatterns(&image);
} // <------------- This line fails , must be the destructor
// of CImage : atlimage.h Line 884, m_hDC == 0
// m_hDC is not NULL in the code
return 0;
}
// Process the image - processing takes < 1 sec
// and the image parameter is not changed
void CAutodetectDialog::SaveImagePatterns(const CImage* image)
{
.........
}这是atlimage.h中失败的代码:
inline HBITMAP CImage::Detach() throw()
{
HBITMAP hBitmap;
ATLASSUME( m_hBitmap != NULL );
ATLASSUME( m_hDC == NULL ); // <------ This guy
hBitmap = m_hBitmap;
...
...
return( hBitmap );
}UPDATE :在注释掉对函数SaveImagePatterns()的调用后,断言失败没有发生。因此,问题必须在该函数中,尽管CImage参数作为const传递。
发布于 2014-05-11 07:09:27
这看起来很可疑:
SaveImagePatterns(&image);因为image是一个局部变量,这取决于SaveImagePatterns如何处理它,这可能会导致问题,因为image对象一旦退出就会被销毁。
发布于 2017-12-28 04:26:45
你在SaveImagePatterns自己打电话给SaveImagePatterns吗?
请注意,image->GetDC()需要与image->ReleaseDC()配对。
所以m_hDC将是NULL。
https://stackoverflow.com/questions/23588951
复制相似问题