得到图像变化率

void showVideo(HWND dlgHwnd, HWND curHwnd)
{

	HDC curHDC = NULL;

	RECT rc; 
	HDC hDesDC = NULL;
	RECT rect;

	HDC curHMemDC = NULL;

	HWND picDWnd = NULL;
	curHDC = ::GetWindowDC(curHwnd);

	//创建兼容DC

	::GetWindowRect(curHwnd, &rc);

	//得到目标位图
	HDC hBufDC;
	HDC hBufDC2;
	HDC hBufDC3;
	HBITMAP hBitmap, hBitmap2, hBitmap3,hBitTemp;
	//创建设备上下文(HDC)
	hBufDC = CreateCompatibleDC(curHDC);
	hBufDC2 = CreateCompatibleDC(curHDC);
	hBufDC3 = CreateCompatibleDC(curHDC);
	//创建HBITMAP
	hBitmap = CreateCompatibleBitmap(curHDC, rc.right - rc.left, rc.bottom - rc.top);
	hBitTemp = (HBITMAP)SelectObject(hBufDC, hBitmap);

	hBitmap2 = CreateCompatibleBitmap(curHDC, rc.right - rc.left, rc.bottom - rc.top);
	hBitTemp = (HBITMAP)SelectObject(hBufDC2, hBitmap2);

	hBitmap3 = CreateCompatibleBitmap(curHDC, rc.right - rc.left, rc.bottom - rc.top);
	hBitTemp = (HBITMAP)SelectObject(hBufDC3, hBitmap3);

	////得到位图缓冲区
	//BitBlt(hBufDC, 0, 0, rc.right - rc.left, rc.bottom - rc.top, curHDC, 0, 0, SRCCOPY);
	for (int i = 0; i < 10; i++)
	{

		//if (FALSE == PrintWindow(curHwnd, hBufDC2, PW_CLIENTONLY))
		//{
		//	::PostMessage(dlgHwnd, WM_IS_VIDEO, 0, (LPARAM)curHwnd);
		//	MessageBox(NULL, _T("Error"), _T("cwnd"), MB_OK);
		//}

		//Sleep(100);

		//if (FALSE == PrintWindow(curHwnd, hBufDC3, PW_CLIENTONLY))
		//{
		//	::PostMessage(dlgHwnd, WM_IS_VIDEO, 0, (LPARAM)curHwnd);
		//	MessageBox(NULL, _T("Error"), _T("cwnd"), MB_OK);
		//}

		BitBlt(hBufDC2, 0, 0, rc.right - rc.left, rc.bottom - rc.top, curHDC, 0, 0, SRCCOPY);
		Sleep(100);
		//得到差分图像
		BitBlt(hBufDC2, 0, 0, rc.right - rc.left, rc.bottom - rc.top, curHDC, 0, 0, SRCINVERT);
		//累加差分分量
		BitBlt(hBufDC, 0, 0, rc.right - rc.left, rc.bottom - rc.top, hBufDC2, 0, 0, SRCPAINT);
	}

	//////得到差分图像

	////处理目标位图

	////得到位图缓冲区
	//BitBlt(hBufDC2, 0, 0, rc.right - rc.left, rc.bottom - rc.top, curHDC, 0, 0, SRCCOPY);
	//Sleep(500);
	////得到差分图像
	//BitBlt(hBufDC2, 0, 0, rc.right - rc.left, rc.bottom - rc.top, curHDC, 0, 0, SRCINVERT);





	////合并差分图
	//BitBlt(hBufDC, 0, 0, rc.right - rc.left, rc.bottom - rc.top, hBufDC2, 0, 0, SRCPAINT);

	//SendMessage(curHwnd, WM_PRINT, (WPARAM)hBufDC, PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT | PRF_OWNED);
	//处理目标位图
	GetGrayBitmap(hBitmap);




	picDWnd = ::GetDlgItem(dlgHwnd, IDC_VISION);



	::GetWindowRect(picDWnd, &rect);

	hDesDC = ::GetWindowDC(picDWnd);

	::SetStretchBltMode(hDesDC, COLORONCOLOR);
	::StretchBlt(hDesDC, 0, 0, rect.right - rect.left, rect.bottom - rect.top, hBufDC, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SRCCOPY);
	Sleep(100);
	//释放内存
	DeleteObject(hBitmap3);
	DeleteObject(hBitmap2);
	DeleteObject(hBitmap);
	DeleteObject(hBitTemp);
	::DeleteDC(hBufDC);
	::DeleteDC(hBufDC2);
	::DeleteDC(hBufDC3);
	::ReleaseDC(curHwnd, curHDC);
	::ReleaseDC(picDWnd, hDesDC);
	//InvalidateRect(picDWnd, &rect, TRUE);



}

猜你喜欢

转载自blog.csdn.net/idwtwt/article/details/79535371