Code Project - Very fast screen capture using DirectX in C#
"Traditionally screen captures are obtained by GDI, but it's slow. In my homemade ambilight project, I needed a fast printscreen and it's posibble: DirectX device has a front buffer - direct image of the screen.
Introduction
Recently I programmed my new project - homemade ambilight. Ambilight is a backlight behind television. The light is the average of some pixels in the screen. In order to get the colors for the ambilight, I needed fast screen capture. After some search, I heard about the front buffer. DirectX devices have this cool property. It contains the actual screen image. It is faster than GDI. DirectX puts an image in the surface object and it's faster for processing than GDI's bitmap.
Requirements and project preparing
Your project must be
STAThread. First you need the DirectX SDK. It contains all the libraries that you need. When you have it downloaded and installed, add to your project the following references:
- Microsoft.DirectX
- Microsoft.DirectX.Direct3D
- Microsoft.DirectX.Direct3DX
If you can't find these in the list of references, then look for these libraries in "C:\Windows\Microsoft.NET\DirectX for Managed Code" and "C:\Windows\Microsoft.NET".
In order to get Direct3D working, we have to add these lines into the app.config (if it doesn't exist, add a new file):
...
This is a different from other approaches I 've seen for grabbing screen-shots...
No comments:
Post a Comment
NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...
ALL comments are moderated. I will review every comment before it will appear on the blog.
Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...
I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...
Please see my comment policy for more information if you are interested.
Thanks,
Greg
PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...