View Single Post
Old 08-14-2015, 01:37 PM
boops boops's Avatar
boops boops boops boops is offline
Join Date: Dec 2006
Location: Holland and France
Posts: 146

Graphics.CopyFromScreen has always been unable to capture DirectX and other "non standard" screen renders. BitBlt is more capable. Maybe this code is worth trying:
	'based on code posted by NoBugz MVP at:

	Public Shared Function CopyFromScreen(ByVal screenRect As Rectangle) As Bitmap
		Dim hDesk As IntPtr = GetDesktopWindow()
		Dim hSrce As IntPtr = GetWindowDC(hDesk)
		Dim hDest As IntPtr = CreateCompatibleDC(hSrce)
		Dim hBmp As IntPtr = CreateCompatibleBitmap(hSrce, screenRect.Width, screenRect.Height)
		Dim hOldBmp As IntPtr = SelectObject(hDest, hBmp)
		BitBlt(hDest, 0, 0, screenRect.Width, screenRect.Height, hSrce, screenRect.Left, screenRect.Top, _
		  CopyPixelOperation.SourceCopy Or CopyPixelOperation.CaptureBlt)
		Dim bmp As Bitmap = Bitmap.FromHbitmap(hBmp)
		SelectObject(hDest, hOldBmp)
		ReleaseDC(hDesk, hSrce)
		Return bmp
	End Function
Can I assume that you know how to declare all those Win32 APIs (GetDesktopWindow, GetWindowDC etc.)? If not, I have a Win32 class somewhere: I'll see if I can dig it out for you tomorrow.

Reply With Quote