|05-20-12, 05:19 AM||#1|
Join Date: Aug 2005
Location: Europe, Slovenia, Koper
[DirectX, C#]Capture screenshot
I'm trying to build an app that would take a fulscreen screenshot.
I've done it in Java using Robots, but that is too slow and it doesn't work on top of directX applications (I get desktop snapshot).
The main point of this app is to take a portion of a screen - a 1/4 on the left side, same amount on the right side and return average RGB values for each side.
So I've started porting app to C# with slimDX and there are some problems.
This is the demo I've cooked using Direct3D9:
adapter = direct3d.Adapters.DefaultAdapter; parameters = new SlimDX.Direct3D9.PresentParameters(); parameters.BackBufferFormat = adapter.CurrentDisplayMode.Format; parameters.BackBufferHeight = adapter.CurrentDisplayMode.Height; parameters.BackBufferWidth = adapter.CurrentDisplayMode.Width; parameters.Multisample = SlimDX.Direct3D9.MultisampleType.None; parameters.SwapEffect = SlimDX.Direct3D9.SwapEffect.Discard; parameters.PresentationInterval = SlimDX.Direct3D9.PresentInterval.Default; parameters.FullScreenRefreshRateInHertz = 0; device = new Device(direct3d, adapter.Adapter, DeviceType.Hardware, parameters.DeviceWindowHandle, CreateFlags.SoftwareVertexProcessing, parameters); surface = Surface.CreateOffscreenPlain(device, adapter.CurrentDisplayMode.Width, adapter.CurrentDisplayMode.Height, Format.A8R8G8B8, Pool.SystemMemory); device.GetFrontBufferData(0, surface); DataRectangle dr = surface.LockRectangle(LockFlags.None); DataStream gs = dr.Data // calculate average RGB for left side Color rgb_l = avcs(gs, 0, cap_top); ...
Is there a better approach to this - I'm more new to graphics programming, but as I understand, what I need is inside front buffer.
Also it would be great if it would work on DX9-DX11