Question Taking a Screenshot of a Fullscreen Game

D4RKKNIGH7

Member
Joined
Sep 13, 2011
Messages
12
Programming Experience
5-10
Hey,

I have... i guess a big problem...

I'm trying to capture and save a screenshot of a full screen game (counter strike source) to be exact.
I have tried many ways but all I ever get it a black screen or my desktop.

I'm trying to take a screenshot once every 30 seconds in a timer.

Any help would be appreciated...

Cheers.
 
What code do you have so far? Check put this library for capturing direct x

+++ removed link +++
Posted wrong link, will amend when I get home.


Sent from my XT910 using Tapatalk 2
 
Last edited:
You would need to use the DirectX SDK (deprecated) or the XNA SDK, both can be downloaded from Microsoft. The video card has to do the work, Windows cannot do it by itself.
 
Direct3D Capture & Mixed mode assembly

So far i have this code

VB.NET:
Imports System.IOImports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D


Public Class Form1
    Public Shared Function CaptureScreenshot(ByVal Device As Direct3D.Device, ByVal Filename As String, ByVal ImageFormat As Direct3D.ImageFileFormat) As Boolean
        Dim B As Direct3D.Surface
        Try
            B = Device.GetBackBuffer(0, 0, Direct3D.BackBufferType.Mono)
            Direct3D.SurfaceLoader.Save(Filename, ImageFormat, B)
            B.Dispose()
        Catch ex As Exception
            Return False
        End Try
        Return True
    End Function


    Public Shared Function CaptureScreenshot(ByVal Device As Direct3D.Device, ByVal Filename As String) As Boolean
        Return CaptureScreenshot(Device, Filename, Direct3D.ImageFileFormat.Bmp)
    End Function


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CaptureScreenshot(Device, "capture.jpg", Direct3D.ImageFileFormat.Bmp)
    End Sub
End Class

Which I got from here (windows - DirectX 10 Screen Capture for Battlefield 3 - Stack Overflow)

Except
VB.NET:
CaptureScreenshot(Device, "capture.jpg", Direct3D.ImageFileFormat.Bmp)
What do i put as the device???

EDIT:
I have added
VB.NET:
Dim D3DDev As Device = Nothing  
 D3DDev = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing)

And it seems to work but when i run the application and press button1 i get
Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
 
I have got the application to load now, but the code

VB.NET:
[LEFT][COLOR=#333333]Dim D3DDev As Device = Nothing  
[/COLOR][COLOR=#333333] D3DDev = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing)[/COLOR][/LEFT]

Does not work, how do i get my device?
 
Last edited:
Hello,

As of now i have got my application taking Screenshots outside of the game... but it only takes them of black screen :(
And when I ingame i get
VB.NET:
A first chance exception of type 'Microsoft.DirectX.Direct3D.DeviceLostException' occurred in Microsoft.DirectX.Direct3D.dll
on this line
VB.NET:
 D3DDev = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, present)


This is the code i'm using

Imports System.IO
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D


Public Class Form1
    Dim i As Integer = 0
    Public Shared Function CaptureScreenshot(ByVal Device As Direct3D.Device, ByVal Filename As String, ByVal ImageFormat As Direct3D.ImageFileFormat) As Boolean
        Dim B As Direct3D.Surface
        Try
            B = Device.GetBackBuffer(0, 0, Direct3D.BackBufferType.Mono)
            Direct3D.SurfaceLoader.Save(Filename, ImageFormat, B)
            B.Dispose()
        Catch ex As Exception
            Return False
        End Try
        Return True
    End Function


    Public Shared Function CaptureScreenshot(ByVal Device As Direct3D.Device, ByVal Filename As String) As Boolean
        Return CaptureScreenshot(Device, Filename, Direct3D.ImageFileFormat.Bmp)
    End Function


    Private Sub SCREENCAP()
        Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width
        Dim intY As Integer = Screen.PrimaryScreen.Bounds.Height


        Dim present As New PresentParameters
        present.BackBufferCount = 1 'the number of backbuffer
        present.BackBufferFormat = Manager.Adapters(0).CurrentDisplayMode.Format
        present.BackBufferHeight = intY
        present.BackBufferWidth = intX
        present.Windowed = True
        present.SwapEffect = SwapEffect.Discard


        Dim D3DDev As Direct3D.Device
        D3DDev = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, present)


        CaptureScreenshot(D3DDev, "c:\capture" & i & ".jpg", Direct3D.ImageFileFormat.Bmp)
        i = i + 1
    End Sub


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        SCREENCAP()
    End Sub
End Class


I'm not really sure what I am doing, never worked with directX or screen capturing before
Any help would be awesome.
Im trying to take fullscreen captures of games.
 
Back
Top