Re: Lower Level Screen Capture
From: Severian (severian_at_chlamydia-is-not-a-flower.com)
Date: Thu, 17 Feb 2005 06:34:27 GMT
On Wed, 16 Feb 2005 08:57:05 -0800, "Dave Anderson"
>I'd like to be able to access the image in the client area of a window or
>even the whole desktop using a VB .NET control. I can use Print Screen to
>take a snapshot into the clipboard and place this in an image control but
>this seems to be a slow and resource intensive solution. Is there a faster
>way to get to the screen image directly? A VB .NET code sample would be ideal
>but even a pointer to the general area of documentation would be a great help.
You can shorten the time somewhat by eliminating the copy to and paste
from the clipboard.
I don't know how to do anything in VB.NET, but the basic Win32 API is
BitBlt. Perhaps someone with VB.NET experience can convert the ideas
below or come up with something more NETish.
1) For generally fastest copying (though it depends on the video
card), Get an HDC compatible with the screen, a compatible bitmap the
size of the virtual screen, and bitblt from the screen HDC to your
HDC. However, the bitmap format will be determined by the screen
(could be 8,15, 16, 24, or 32 bits). If you're saving these for later
processing, this may be the way to go.
The relevent Win32API calls are: CreateCompatibleDC(),
CreateCompatibleBitmap(), SelectObject(), BitBlt(), GetObject(), and
GetBitmapBits(). (When done, select the original bitmap into the
compatible DC and DeleteObject(), DeleteDC() and release the screen
2) For easier-to-digest work, create a 24-bit DIB instead of a
compatible bitmap (use CreateDIBSection rather than
CreateCompatibleBitmap), select that into the HDC, and BitBlt there.
This will convert the pixels to BGR standard, and you can access the
pixels and bitmap info directly from memory rather than using
GetObject() and GetBitmapBits().