Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 DirectX 9 Screenshot
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sharratt
Neophyte

3 Posts

Posted - Feb 04 2005 :  1:25:10 PM  Show Profile  Reply with Quote
I have wrrited the code to create a screenshot using DirectX 9 it would seem to crash and error if you dont have focus off the form bt i need to still take a screenshot regardless of whether the form has focus or not.

The process in which i am getting a screenshot is:

1. Create device to current form in windowed mode
2. Create Surface from Plain
3. Get front buffer
4. Send surface to file

As i say it works perfect if you have focu on the form but i want to be in another application when it takes it!!

Any Ideas?

Lachlan87
Moderator

USA
160 Posts

Posted - Feb 04 2005 :  2:26:50 PM  Show Profile  Reply with Quote
Print screen will work if your game runs in windowed mode.

I assume your using Direct Input for you keyboard handling. . .is you DirectInput device running in background and non-exclusive mode?

Go to Top of Page

sharratt
Neophyte

3 Posts

Posted - Feb 04 2005 :  9:22:35 PM  Show Profile  Reply with Quote
Pritn Screen is not an option unfortunatly does this mean that using DirectX i cant loose focus of which the device was created for?
Go to Top of Page

timbo152k
Squire

Canada
25 Posts

Posted - Feb 04 2005 :  11:02:03 PM  Show Profile  Visit timbo152k's Homepage  Send timbo152k an AOL message  Click to see timbo152k's MSN Messenger address  Send timbo152k a Yahoo! Message  Reply with Quote
dont create a device to the WINDOW to take it from.. create a device to the SCREEN - use the API call GetDC() as follows:

Dim ScreenDC as long

ScreenDC = GetDC(0) 'gets the DC of the entire screen area..

.. then copy that to a file or another device for saving or whatever.. heck you could even use BitBlt for this.
Go to Top of Page

sharratt
Neophyte

3 Posts

Posted - Feb 06 2005 :  09:39:03 AM  Show Profile  Reply with Quote
Hmm I tried calling GetDC as Inprt and seems to hang on creating a device I have checked my present params and they seem ok if anyone has an example of creating a DirectX 9 Device successfully grabbing te full screen that would be so much appreciated.

Thanks for comments so far really want to crack this!

Jon
Go to Top of Page

Lachlan87
Moderator

USA
160 Posts

Posted - Feb 07 2005 :  07:51:08 AM  Show Profile  Reply with Quote
OK, I found the easy way:

Dim surf As Surface = device.GetBackBuffer(0, 0, BackBufferType.Mono)  
SurfaceLoader.Save("ScreenShot.bmp", ImageFileFormat.Bmp, surf)  
surf.Dispose()  


Create a new surface, give it the backbuffer data, and save it to a bitmap using the built-in SurfaceLoader class. I expect this code is self-explanatory, but if you need more help, don't be embarrassed to ask!

Edited by - Lachlan87 on Feb 07 2005 09:04:37 AM
Go to Top of Page

cbx
Swordmaster

Canada
296 Posts

Posted - Feb 07 2005 :  08:40:34 AM  Show Profile  Visit cbx's Homepage  Send cbx an ICQ Message  Click to see cbx's MSN Messenger address  Send cbx a Yahoo! Message  Reply with Quote
This is the code I often use. It should work in windowed mode all the time. But it may not work in a fullscreen mode that has lost focus.

#Region " CaptureScreenshot ... "  
    ''' <summary>  
    ''' Captures a screen shot.  
    ''' </summary>  
    ''' <param name="Device">The revice to capture the screen shot from.</param>  
    ''' <param name="Filename">The filename to save the image file to.</param>  
    ''' <param name="ImageFormat">The file format to save the image as.</param>  
    ''' <returns>If the screen capture was successfull then CaptureScreenshot will return True.</returns>  
    ''' <remarks>  
    ''' This method will save a screen shot using the specified image format from the ImageFormat parameter regardless  
    ''' of what filename extention is specified in the Filename parameter.  
    ''' Note that the CaptureScreenshot method saves the contents of the devices backbuffer, so make sure you don't  
    ''' do a clear before capturing a screen shot.  
    ''' </remarks>  
    Public Function CaptureScreenshot(ByVal Filename As String, ByVal ImageFormat As Direct3D.ImageFileFormat) As Boolean
        Try
            Dim B As Direct3D.Surface  
            ' get back buffer  
            B = mobjDevice.GetBackBuffer(0, 0, Direct3D.BackBufferType.Mono)  
  
            ' save capture image  
            Direct3D.SurfaceLoader.Save(Filename, ImageFormat, B)  
            B.Dispose()  
        Catch ex As Exception  
            Return False
        End Try
  
        Return True
    End Function
  
    ''' <summary>  
    ''' Captures a screen shot.  
    ''' </summary>  
    ''' <param name="Device">The revice to capture the screen shot from.</param>  
    ''' <param name="Filename">The filename to save the image file to.</param>  
    ''' <param name="ImageFormat">The file format to save the image as.</param>  
    ''' <returns>If the screen capture was successfull then CaptureScreenshot will return True.</returns>  
    ''' <remarks>  
    ''' Since no image format is specified CaptureScreenshot will try to save the image using the *.bmp format.  
    ''' Regardless of what filename extention is specified in the Filename parameter.  
    ''' Note that the CaptureScreenshot method saves the contents of the devices backbuffer, so make sure you don't  
    ''' do a clear before capturing a screen shot.  
    ''' </remarks>  
    Public Function CaptureScreenshot(ByVal Filename As String) As Boolean
        Return CaptureScreenshot(Filename, Direct3D.ImageFileFormat.Bmp)  
    End Function
#End Region  



Created by: X
http://www.createdbyx.com/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.16 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.