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

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:
Code:
	'based on code posted by NoBugz MVP at:
	'http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/474450b9-e260-4369-9efb-0d57a5b2e06d

	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)
		DeleteObject(hBmp)
		DeleteDC(hDest)
		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.

BB
Reply With Quote