http://social.msdn.microsoft.com/forums/en-US/windowssdk/thread/2408d395-5c57-494c-bb3c-ba4c15512c05
Hello!
I'm having a problem with BitBlt in my application.
I capture the frames of a webcam and display them with BitBlt directly on the main window. But after a few minutes the drawing stops, although the capturing is still running (i'm saving each 10th image in order to check that).
So the images are not drawn anymore after some time, and even the Windows " picture and fax viewer" does not work anymore when this problem occurs.
The capturing runs in an own thread and each time a new frame is taken it is directly painted on the screen to get a live stream of the camera:
Could you please tell me if I'm making any mistake in this code or if the problem is somewhere else?
Thanks in advance,
Daniel
I'm having a problem with BitBlt in my application.
I capture the frames of a webcam and display them with BitBlt directly on the main window. But after a few minutes the drawing stops, although the capturing is still running (i'm saving each 10th image in order to check that).
So the images are not drawn anymore after some time, and even the Windows " picture and fax viewer" does not work anymore when this problem occurs.
The capturing runs in an own thread and each time a new frame is taken it is directly painted on the screen to get a live stream of the camera:
if(VI.isFrameNew(device1))
{
hdc1 = GetDC(hWnd);
imageBuffer = VI.getPixels(device1, false, false);
cxImage.CreateFromArray((BYTE*)imageBuffer, VI.getWidth(device1), VI.getHeight(device1), 24, VI.getWidth(device1)*3, false);
bmp = cxImage.MakeBitmap(hdc1);
hdcMem = CreateCompatibleDC(hdc1);
hBitmapPrev = (HBITMAP)SelectObject(hdcMem, bmp);
BitBlt(hdc1, 20, 40, VI.getWidth(device1), VI.getHeight(device1), hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hBitmapPrev);
DeleteDC(hdcMem);
DeleteDC(hdc1);
imageBuffer = NULL;
}
Could you please tell me if I'm making any mistake in this code or if the problem is somewhere else?
Thanks in advance,
Daniel
-------------------------------------
I don't know if this is the source of your error, but you should "ReleaseDC(hdc1)"
See the documentation of DeleteDC at the msdn.
Hope this helps.
See the documentation of DeleteDC at the msdn.
Hope this helps.
------------------------
Thanks for your reply.
But actually I was using ReleaseDC,i forgot to post this part of the code.
Here is the whole Thread-Method:
Any other ideas about a possible reason for my problem?
Thanks a lot,
Daniel
EDIT: I could solve it now. My mistake was i didn't delete the Bitmaps. By adding
DeleteObject(bmp);
DeleteObject(hBitmapPrev);
everything works fine now.
Thanks a lot, alex! Your idea with releasing resources made me remember that I have to delete these objects too :-)
But actually I was using ReleaseDC,i forgot to post this part of the code.
Here is the whole Thread-Method:
DWORD WINAPI ThreadProc( LPVOID pvoid )
{
HDC hdc1, hdcMem;
HBITMAP bmp, hBitmapPrev;
CxImage cxImage;
unsigned char* imageBuffer; //Here is the camera image stored
while(true)
{
hdc1 = GetDC(hWnd);
if(VI.isFrameNew(device1))
{
imageBuffer = VI.getPixels(device1, false, false);
cxImage.CreateFromArray((BYTE*)imageBuffer, VI.getWidth(device1), VI.getHeight(device1), 24, VI.getWidth(device1)*3, false);
bmp = cxImage.MakeBitmap(hdc1);
hdcMem = CreateCompatibleDC(hdc1);
hBitmapPrev = (HBITMAP)SelectObject(hdcMem, bmp);
BitBlt(hdc1, 20, 40, VI.getWidth(device1), VI.getHeight(device1), hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hBitmapPrev);
DeleteDC(hdcMem);
DeleteDC(hdc1);
imageBuffer = NULL;
}
ReleaseDC(hWnd, hdcMem);
ReleaseDC(hWnd, hdc1);
}
return 0;
}
Any other ideas about a possible reason for my problem?
Thanks a lot,
Daniel
EDIT: I could solve it now. My mistake was i didn't delete the Bitmaps. By adding
DeleteObject(bmp);
DeleteObject(hBitmapPrev);
everything works fine now.
Thanks a lot, alex! Your idea with releasing resources made me remember that I have to delete these objects too :-)
本文介绍了一个关于使用BitBlt在应用程序中实时显示摄像头帧的问题及解决方案。作者遇到在几分钟后绘制停止的情况,通过确保正确释放资源(如删除Bitmap对象)解决了问题。
2177

被折叠的 条评论
为什么被折叠?



