Results 1 to 33 of 33

Thread: Save a screenshot?

Hybrid View

  1. #1
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Save a screenshot?

    Since your program doesn't have the focus when you want to save the screen. You might want to look into using the RegisterHotKey function to register a hotkey to be used to save the screen. You could then use the code posted by Hack above in the callback function to save the image.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Location
    Cleveland, Ohio
    Posts
    255

    Re: Save a screenshot?

    What makes you so sure I dont have focus? Like i said, i have already hooked the keyboard for use of it ingame, so i can just press a button and it saves a screen.

    so yes i do have focus. i will try the code now, thanks

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Save a screenshot?

    I'm sorry I didn't read your origional post careful enough.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Location
    Cleveland, Ohio
    Posts
    255

    Re: Save a screenshot?

    Does anyone know if i could possibly blueprint all these images im saving with some simple text at the bottom or something?

    I have the filenames saved based on the time right now.

    BTW can i save them as jpg instead of bmp because bmp is large files

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Save a screenshot?

    You could put the image inside a memory dc and use DrawText and then store it or simply put it in a hidden PictureBox and use the Print statement and then save the image (the PicBox need to have the AutoRedraw property set). To save as a JPG you need some third party control. I think I have a simple BMP2JPG dll somewhere, I'll see if I can dig it out for you.

  6. #6
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Save a screenshot?

    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  7. #7
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Save a screenshot?

    Here's the DirectX approach to saving snapshots. You can save it as bmp as well as jpg or any other format. DirectX does it for you.

    VB Code:
    1. Public Sub DirectX_Snapshot(ByVal File_Path As String)
    2.  
    3.     Dim Surface As Direct3DSurface8
    4.     Dim SrcPalette As PALETTEENTRY
    5.     Dim SrcRect As RECT
    6.     Dim Direct3D_Display_Mode As D3DDISPLAYMODE
    7.  
    8.     'get display dimensions
    9.     Direct3D_Device.GetDisplayMode Direct3D_Display_Mode
    10.  
    11.     'create a surface to put front buffer on,
    12.     'GetFrontBuffer always returns D3DFMT_A8R8G8B8
    13.     Set Surface = Direct3D_Device.CreateImageSurface(Direct3D_Display_Mode.Width, Direct3D_Display_Mode.Height, D3DFMT_A8R8G8B8)
    14.  
    15.     'get data from front buffer
    16.     Direct3D_Device.GetFrontBuffer Surface
    17.  
    18.     'we are saving entire area of this surface
    19.    
    20.     With SrcRect
    21.    
    22.         .Left = 0
    23.         .Right = Direct3D_Display_Mode.Width
    24.         .Top = 0
    25.         .bottom = Direct3D_Display_Mode.Height
    26.        
    27.     End With
    28.  
    29.     'save this surface to a BMP file
    30.     'Direct3DX.SaveSurfaceToFile File_Path, D3DXIFF_BMP, Surface, SrcPalette, SrcRect
    31.  
    32.     'save this surface to a JPG file
    33.     Direct3DX.SaveSurfaceToFile File_Path, D3DXIFF_JPG, Surface, SrcPalette, SrcRect
    34.  
    35. 'Here are some more formats
    36.  
    37. 'D3DXIFF_TGA
    38. 'D3DXIFF_PNG
    39. 'D3DXIFF_DIB
    40. 'D3DXIFF_DDS
    41. 'D3DXIFF_PPM
    42. 'D3DXIFF_FORCE_DWORD <---- Don't know what that does.
    43.  
    44. End Sub

    And in your game loop, you put this in:

    VB Code:
    1. 'Declare this variable in the General Declarations
    2.  
    3.        Dim Snapshot_Number As Long
    4.  
    5.        'Then put this in your loop
    6.  
    7.         If DirectInput_Key_State(DIK_F12) Then
    8.            
    9.             If Dir$(App.Path & "\Snapshots\", vbDirectory) = "" Then
    10.                
    11.                 MkDir App.Path & "\Snapshots\"
    12.                
    13.             End If
    14.            
    15.             If Dir$(App.Path & "\Snapshots\SNAP" & Format(Snapshot_Number, "####") & ".jpg") = "" Then
    16.            
    17.                 DirectX_Snapshot App.Path & "\Snapshots\SNAP" & Format(Snapshot_Number, "####") & ".jpg"
    18.            
    19.             End If
    20.            
    21.             While Dir$(App.Path & "\Snapshots\SNAP" & Format(Snapshot_Number, "####") & ".jpg") <> ""
    22.                
    23.                 DoEvents
    24.                
    25.                 Snapshot_Number = Snapshot_Number + 1
    26.                
    27.             Wend
    28.            
    29.         End If

  8. #8
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Save a screenshot?

    Hi Jacob Roman,

    If any of us want to build a stand alone pgm using your code, is there any other things we need to declare (or know), to build into the pgm.

    Your sample aimed at jacob123, assumes that he has Directx 'stuff' already in his pgm (which he has).

    Thanks for sharing,
    Rob C

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width