Post

 Resources 

Console

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

 All Forums
 VBGamer
 VBGamer
 DirectX 9 Screenshot

Note: You must be registered in order to post a reply.

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List Spell Checker
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert an File
Check here to include your profile signature.
Check here to subscribe to this topic.
    

T O P I C    R E V I E W
sharratt Posted - Feb 04 2005 : 1:25:10 PM
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?
6   L A T E S T    R E P L I E S    (Newest First)
cbx Posted - Feb 07 2005 : 08:40:34 AM
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  
Lachlan87 Posted - Feb 07 2005 : 07:51:08 AM
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!
sharratt Posted - Feb 06 2005 : 09:39:03 AM
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
timbo152k Posted - Feb 04 2005 : 11:02:03 PM
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.
sharratt Posted - Feb 04 2005 : 9:22:35 PM
Pritn Screen is not an option unfortunatly does this mean that using DirectX i cant loose focus of which the device was created for?
Lachlan87 Posted - Feb 04 2005 : 2:26:50 PM
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?

VBGamer © Go To Top Of Page
This page was generated in 0.19 seconds. Snitz Forums 2000

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