windows系统抓屏技术

一,GDI

GDI抓屏

       所有的windows版本都通用的抓屏方式,这种抓屏方式相对比较慢,抓取一帧1080p的桌面需要5~8ms左右的时间。而且在vista以后的系统上,如果启用Aero特效的话,效率较低。

        HDC window_dc = ::GetDC(::GetDesktopWindow());
		winWidth_ = GetDeviceCaps(window_dc, HORZRES);
		winHeight_ = GetDeviceCaps(window_dc, VERTRES);
		

		hTemp_ = CreateCompatibleDC(window_dc);
		memBitmap_ = CreateCompatibleBitmap(window_dc, winWidth_, winHeight_);
		oldmemBitmap_ = (HBITMAP)SelectObject(hTemp_, memBitmap_);

		int rgbSize = 4 * winWidth_ * winHeight_;

		bih_.biBitCount = 32;
		bih_.biCompression = BI_RGB;
		bih_.biHeight = -winHeight_;
		bih_.biPlanes = 1;
		bih_.biSize = sizeof(BITMAPINFOHEADER);
		bih_.biSizeImage = rgbSize;
		bih_.biWidth = winWidth_;


		BitBlt(hTemp_, 0, 0, winWidth_, winHeight_, window_dc, 0, 0, SRCCOPY | CAPTUREBLT);

		CURSORINFO ci;
		ci.cbSize = sizeof(CURSORINFO);
		GetCursorInfo(&ci);
		DrawIcon(hTemp_, ci.ptScreenPos.x, ci.ptScreenPos.y, ci.hCursor);

		GetDIBits(hTemp_, memBitmap_,
			0,
			winHeight_,
			rgbPtr_,
			(LPBITMAPINFO)&bih_,
			DIB_RGB_COLORS
		);

 
		// 存位图文件,注意:rgbPtr_存的是ARgb32的数据 ;

		DeleteDC(hTemp_);
		::ReleaseDC(::GetDesktopWindow(), window_dc);
		DeleteObject(memBitmap_);

二,DDraw

三,D3d

四, DXGI

       适用于win8以后的操作系统,win7以前的系统无法使用此接口,不支持抓局部屏,只能是全屏

猜你喜欢

转载自blog.csdn.net/machh/article/details/83056869