Go Back   nV News Forums > Software Forums > Software Development

Newegg Daily Deals

Thread Tools
Old 05-20-12, 05:19 AM   #1
kriko's Avatar
Join Date: Aug 2005
Location: Europe, Slovenia, Koper
Posts: 515
Default [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);
When I run a fulscreen game e.g. Portal - I get captured only desktop (I've tried to save surface to file for preview), same story is with NFS run, which is a DX11 game.

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
kriko is offline   Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

All times are GMT -5. The time now is 05:27 AM.

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.