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.
Im not sure how that would help that seems to be for playing AVIs.
Right now I'm using VB.NET - Screenshot to jpeg... - VBForums
I have disabled aero and it still doesnt work.
Anyone have any ideas?
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.
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
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
Code:
Dim D3DDev As Device = Nothing
D3DDev = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing)
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.
Bookmarks