screen capture
screen capture
screen capture
screen capture
screen capture
screen capture screen capture screen capture screen capture screen capture screen capture screen capture screen capture
screen capture screen capture
screen capture
Go Back  Xtreme Visual Basic Talk > > > > screen capture


Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2012, 11:47 AM
SCT_NSKY SCT_NSKY is offline
Freshman
 
Join Date: Dec 2003
Location: Sweden
Posts: 45
Default screen capture


Im trying to take screen shot of game (bf3) with this code

Code:
Private DX As DirectX8 'The master DirectX object.
Private Direct3D As Direct3D8 'Controls all things 3D.
Private Direct3D_Device As Direct3DDevice8 'Represents the hardware rendering.
Private Direct3DX As D3DX8

Private Sub Snapshot(ByVal File_Path As String)

Dim Display_Mode As D3DDISPLAYMODE 'Display mode desciption.
    Dim Direct3D_Window As D3DPRESENT_PARAMETERS 'Backbuffer and viewport description.

    Set DX = New DirectX8 'Creates the DirectX object.
    Set Direct3D = DX.Direct3DCreate() 'Creates the Direct3D object using the DirectX object.
    Set Direct3DX = New D3DX8

    Direct3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, Display_Mode  'Use the current display mode that you  'are already on. Incase you are confused, I'm'talking about your current screen resolution. ;)
    Direct3D_Window.Windowed = True 'The app will be in windowed mode.

    Direct3D_Window.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC 'Refresh when the monitor does.
    Direct3D_Window.BackBufferFormat = Display_Mode.Format 'Sets the format that was retrieved into the backbuffer.

    'Creates the rendering device with some useful info, along with the info
    'we've already setup for Direct3D_Window.
    Set Direct3D_Device = Direct3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Direct3D_Window)

    Dim Surface As Direct3DSurface8
    Dim SrcPalette As PALETTEENTRY
    Dim SrcRect As RECT
    Dim Direct3D_Display_Mode As D3DDISPLAYMODE

    'get display dimensions
    Direct3D_Device.GetDisplayMode Direct3D_Display_Mode

    'create a surface to put front buffer on,
    'GetFrontBuffer always returns D3DFMT_A8R8G8B8
    Set Surface = Direct3D_Device.CreateImageSurface(Direct3D_Display_Mode.Width, Direct3D_Display_Mode.Height, D3DFMT_A8R8G8B8)

    'get data from front buffer
    Direct3D_Device.GetFrontBuffer Surface

    'we are saving entire area of this surface
    With SrcRect
        .Left = 0
        .Right = Direct3D_Display_Mode.Width
        .Top = 0
        .bottom = Direct3D_Display_Mode.Height
    End With

    'save this surface to a BMP file
    Direct3DX.SaveSurfaceToFile File_Path, D3DXIFF_BMP, Surface, SrcPalette, SrcRect

    'Unload all of the DirectX objects
    Set Direct3D_Device = Nothing
    Set Direct3D = Nothing
    Set DX = Nothing
End sub
it works taking a ss of windows desktop, but when try to take a ss in game it hangs at this line
Set Direct3D_Device = Direct3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Direct3D_Window)

but if run the game in window mode it works to. What are i doing wrong?
Reply With Quote
  #2  
Old 06-29-2012, 06:23 PM
hDC_0screen capture hDC_0 is offline
Contributor

* Expert *
 
Join Date: Feb 2004
Posts: 559
Default DirectX8 - screenshot options..

Its not easy to take a screenshot of DirectX screens.
(although DirectX screenshot-ting has been discussed several times on the xvbt forums..)

There is a utility call "Fraps" that does it but there was a lot of hooking involved if you read this case study.

I found some code here that looks like a function designed to take screenshots of DirectX8 screens:
Quote:
Public Function TakeScreenShot(Direct3DDevice As Direct3DDevice8, D3DX As D3DX8, _
ByVal ScreenHeight As Long, ByVal ScreenWidth As Long, Optional ByVal FilePath As String) As Boolean
' This function takes a screenshot of DirectX's front buffer.
' Returns true or false depending on if it worked.

' Declare variables
Dim ScreenShot As Direct3DSurface8 ' The pointer to our new screen buffer which will be saved to a file
Dim Filename As String ' The file name of the screen shot
Dim x As Long ' The loop holder
Dim PalEntry As PALETTEENTRY ' The pallette entry used to save the BMP
Dim SourceRect As RECT ' The source rectangle used when saving the BMP

' See if the path exists
If Len(FilePath) = 0 then FilePath = App.Path
If Right$(FilePath, 1) <> "\" Then FilePath = FilePath & "\"
If Len(Dir(FilePath, vbDirectory)) = 0 Then Exit Function

' Find a file path that doesn't exist
Do
x = x + 1
Filename = FilePath & "screen" & Format(x, "0000") & ".bmp"
Loop Until Len(Dir(Filename)) = 0

' 1. Create the image surface
Set ScreenShot = Direct3DDevice.CreateImageSurface(ScreenWidth, ScreenHeight, D3DFMT_A8R8G8B8)
If ScreenShot Is Nothing Then Exit Function ' Check if there was an error

' 2. Put the front buffer into the screen shot surface
Direct3DDevice.GetFrontBuffer ScreenShot

' 3. Save the whole screen as a BMP
SourceRect.Right = ScreenWidth
SourceRect.bottom = ScreenHeight
D3DX.SaveSurfaceToFile Filename, D3DXIFF_BMP, ScreenShot, PalEntry, SourceRect

' Delete allocated memory and return the result
Set ScreenShot = Nothing
TakeScreenShot = True
End Function
Other than that your two options might be to write some code that
presses the print screen key programmatically or use the WinAPI GetDC(0) function.

There are plenty examples of these around the internet. A few links to get you started (1, 2, 3).

The bad thing about these approaches is that DirectX communicates with the video card
on a level below the Windows API, so depending on timing you may or may not
be able to capture what you want
based on how fast things are happening on screen.

The other thing is that by default (without using GDI+ or any third party jpeg-ing dlls),
it's hard for VB6 to save a screenshot in anything but bitmap (.bmp) format,
which can result in some large files with bigger monitors.

Last edited by hDC_0; 06-29-2012 at 06:31 PM.
Reply With Quote
  #3  
Old 06-30-2012, 03:31 AM
SCT_NSKY SCT_NSKY is offline
Freshman
 
Join Date: Dec 2003
Location: Sweden
Posts: 45
Default

I have done allot of goggling these couple of days and i think that its to hard to do in vb6.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
screen capture
screen capture
screen capture screen capture
screen capture
screen capture
screen capture screen capture screen capture screen capture screen capture screen capture screen capture
screen capture
screen capture
 
screen capture
screen capture
 
-->