GPWiki.org
GPWiki.org
It is currently Fri May 24, 2013 2:46 am

All times are UTC




Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: DirectX Game Screenshot
PostPosted: Fri Feb 03, 2012 9:59 am 
Rookie

Joined: Fri Feb 03, 2012 9:57 am
Posts: 4
Software: Visual Basic 2008
My problem:
I make a program for taking screenshots from the game, this is the current code that I use:

Code:
Dim bounds As Rectangle
            Dim screenshot As System.Drawing.Bitmap
            Dim graph As Graphics
            bounds = Screen.PrimaryScreen.Bounds
            screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            graph = Graphics.FromImage(screenshot)
            graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
            PictureBox1.Image = screenshot


and it works great when i need to take a desktop screenshot, but when i try take a game screenshot it does not work! I read on the internet and it says that I need to take screenshots from DirectX. The problem is that I never worked with DirectX and I need your help, any help is welcome if it is related to my problem, I would appreciate if you have some kind of example.





Thank you!


Top
 Profile  
 
PostPosted: Tue Mar 20, 2012 8:01 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
Well i havent done alot of dx with vb lately , i have moved to xna and c# but i always keep my old code.
Here is a simple class i have which does exactly what you want.

Code:
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D

Public Class ScreenShot

    Public dxDevice As Direct3D.Device

    Public Sub New(ByVal Device As Direct3D.Device)
        dxDevice = Device
    End Sub

    Public Sub TakeShot(ByVal ScreenShotPath As String)
        Dim d As DateTime = System.DateTime.Now
        Dim datetime As String = d.Date.Day.ToString & "." & d.Date.Month.ToString & "." & d.Date.Year.ToString & " " & d.TimeOfDay.Hours & "." & d.TimeOfDay.Minutes & "." & d.TimeOfDay.Seconds
        Dim file As String = ScreenShotPath & "\Screenshot " & datetime & ".jpg"
        SurfaceLoader.Save(file, ImageFileFormat.Jpg, dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono))
    End Sub

End Class


i hope this helps.


Top
 Profile  
 
PostPosted: Fri Mar 30, 2012 11:07 am 
Rookie

Joined: Fri Feb 03, 2012 9:57 am
Posts: 4
Error:

'SurfaceLoader' is not declared.
and

'ImageFileFormat' is not declared.


Top
 Profile  
 
PostPosted: Sat Mar 31, 2012 1:58 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
make sure your importing the right imports and also make sure you are ref the latest managed dx libs, and d3dx.


Top
 Profile  
 
PostPosted: Sat Mar 31, 2012 7:12 pm 
Rookie

Joined: Fri Feb 03, 2012 9:57 am
Posts: 4
ok i fix that!, now how can i test it?


Top
 Profile  
 
PostPosted: Tue Apr 03, 2012 7:11 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
just add a keystroke to your, form using the onkeypress event for example the letter s, then just run the function and point it ot a folder for instace, create a screenshot folder in you application path folder. example:

Code:
dim ss as screenshot = new screenshot(device)

ss.TakeShot(application.startuppath & "\screenshots\")



this should let you know it works.


Top
 Profile  
 
PostPosted: Thu Apr 12, 2012 10:27 am 
Sorry to jump in but when I use you code and call it via a button click...

Code:
        Dim scn As Screenshot = New Screenshot(Device)
        scn.TakeShot(My.Application.Info.DirectoryPath & "\screenshots\")


I always get the error 'Device is a type and cannot be used as an expression.

Any clue?


Top
  
 
PostPosted: Sat Apr 14, 2012 7:42 am 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
yeah you have to pass your dxdevice from your app not just a ref to the type. Thats just an example. In your main app you have a dxdevice defined right? just pass that.


Top
 Profile  
 
PostPosted: Sun Apr 15, 2012 7:10 pm 
Sorry to be such an annoyance but when you say "pass your dxdevice from your app not just a ref to the type" I don't actually understand? I have no knowledge with DirectX and am confused upon passing my dxdevice from my app?

Cheers anyway!


Top
  
 
PostPosted: Thu Apr 19, 2012 6:26 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
well you just pass a ref to your dxdevice.

for instance in your main app if you have the main dx device defined as dxdevice, just pass that as a ref to the class. as long as the device is not nothing then it should work fine.


Top
 Profile  
 
PostPosted: Fri Apr 20, 2012 2:28 pm 
Couldn't you just use "dxdevice" instead of "Device" ?


Top
  
 
PostPosted: Fri Apr 20, 2012 6:25 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
dxdevice is just an example what ever you named your main dx class variable. Look i do understand you want to get things working, but maybe its a good idea to just write a simple program first and get to grips the basics of programming trust me it will make the process alot easier in the long run if you try just to jump right in and dont understand what it is you are doing it will take you years, and alot of rewrites before you actually get anything working. by the way you are probably better off using c# and xna then vb and managed dx or vb and xna its much better to code with. It took me years to come to the realisation that vb was just too slow, well not too slow but the amount of work and optimization it neded to do what in c# i can just do quickly then optmize later makes a big difference.


Top
 Profile  
 
PostPosted: Sat Apr 21, 2012 11:52 am 
I have a decent knowledge of VB, It's just that DirectX Is a completely new thing to me... I've fixed all errors other than one which is for:

Code:
SurfaceLoader.Save(file, ImageFileFormat.Jpg, dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono))


"Object reference not set to an instance of an object error"

I really don't know which part of this line is not an object?


Cheers.


Top
  
 
PostPosted: Sat Apr 21, 2012 8:02 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
well the only object that could be null is dxdevice. Are you sure it if fully initialized.


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 9:13 pm 
I've used the same code as you but set it to run each tick of a timer so I presume it is?


Top
  
 
PostPosted: Mon Apr 23, 2012 7:17 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
dont use it each tick, just add a keyboard event for it like the s key, but it should still work it just means that your passing a numm ref to the class, to be ohnest i need to see some more code to be able to figure out what is causing it.


Top
 Profile  
 
PostPosted: Mon Apr 23, 2012 9:25 pm 
screenshot class:

Code:
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D


Public Class Screenshot

    Public dxDevice As Direct3D.Device

    Public Sub New(ByVal Device As Direct3D.Device)

        dxDevice = Device

    End Sub

    Sub New()
        ' TODO: Complete member initialization
    End Sub

    Public Sub TakeShot(ByVal ScreenShotPath As String)
        Dim d As DateTime = System.DateTime.Now
        Dim datetime As String = d.Date.Day.ToString & "/" & d.Date.Month.ToString & "/" & d.Date.Year.ToString & ":" & d.TimeOfDay.Hours & "/" & d.TimeOfDay.Minutes
        Dim file As String = ScreenShotPath & "Screenshot " & datetime & ".jpg"
        SurfaceLoader.Save(file, ImageFileFormat.Jpg, dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono))
    End Sub

End Class


Code that's enacted every 60 seconds:

Code:
Dim Screenshotnew As New Screenshot
Dim screeny As Screenshot = New Screenshot(Screenshotnew.dxDevice)
screeny.TakeShot(My.Application.Info.DirectoryPath & "\screenshots\")


Top
  
 
PostPosted: Tue Apr 24, 2012 8:24 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
Guest wrote:
screenshot class:

Code:
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D


Public Class Screenshot

    Public dxDevice As Direct3D.Device

    Public Sub New(ByVal Device As Direct3D.Device)

        dxDevice = Device

    End Sub

    Sub New()
        ' TODO: Complete member initialization
    End Sub

    Public Sub TakeShot(ByVal ScreenShotPath As String)
        Dim d As DateTime = System.DateTime.Now
        Dim datetime As String = d.Date.Day.ToString & "/" & d.Date.Month.ToString & "/" & d.Date.Year.ToString & ":" & d.TimeOfDay.Hours & "/" & d.TimeOfDay.Minutes
        Dim file As String = ScreenShotPath & "Screenshot " & datetime & ".jpg"
        SurfaceLoader.Save(file, ImageFileFormat.Jpg, dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono))
    End Sub

End Class


Code that's enacted every 60 seconds:

Code:
Dim Screenshotnew As New Screenshot
Dim screeny As Screenshot = New Screenshot(Screenshotnew.dxDevice)
screeny.TakeShot(My.Application.Info.DirectoryPath & "\screenshots\")



well theres your problem your passing the null ref to the dxdevice in the class, you need to pass the dx device you have defined and initialized in you main form.


Top
 Profile  
 
PostPosted: Tue Apr 24, 2012 9:27 pm 
I haven't done that, nor do I really get the grasp on what I have to do to assert it? :/


Top
  
 
PostPosted: Wed Apr 25, 2012 6:39 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
Code:
Dim Screenshotnew As New Screenshot - get rid of this why do you have this

Dim screeny As Screenshot = New Screenshot(directx device from your form)
screeny.TakeShot(My.Application.Info.DirectoryPath & "\screenshots\")






this is the best way i can tell ya how to do it. unless i see your full code i cant fix it. also dont create a new instance of the screenshot class everytime you take a screenshot just initialize it once at startup then call the takeshot function. you just need a ref to the device your using to render , you just dumping the backbuffer in to a image file.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group