-
Nov 25th, 2014, 05:03 PM
#1
Thread Starter
Junior Member
Game Screenshots
I am in the last few stages of developing my game.
I am trying to implement the ability to take screenshots of the current game state.
The problem I am having is that my game draws using graphics objects.
I am wondering if there is any way of saving the graphics object as an image? or convert it into an image, which can then be saved?
Another Idea I have had is potentially creating a new bitmap, then drawing everything onto that, but I dont think there is a way to draw onto a bitmap, like you can with graphics?
Any help is appreciated
-
Nov 25th, 2014, 05:20 PM
#2
Re: Game Screenshots
I don't know what you mean.
You use a Graphics object to draw on things, i.e. to the form, or a panel, or a picturebox, so you can get a graphics object from an image (which holds a bitmap) and draw on it.
But typically, if you wanted to take a screenshot, that is what you would do, using the Graphics.CopyFromScreen method to copy an area of the screen.
-
Nov 25th, 2014, 05:23 PM
#3
Thread Starter
Junior Member
Re: Game Screenshots
I basically want to copy what is on the graphics object, and save it as an image in a file.
But I cannot find how to do that, if it is even possible.
-
Nov 25th, 2014, 05:25 PM
#4
Re: Game Screenshots
What are you calling a graphics object?
Give an example of how you're drawing.
-
Nov 25th, 2014, 05:27 PM
#5
Thread Starter
Junior Member
Re: Game Screenshots
Declaring
Dim ScreenGraphics as Graphics
Enabling
ScreenGraphics = Me.CreateGraphics
Drawing
ScreenGraphics.DrawRectangle(20,20,50,50)
This is then wiped and redraw every 'game tick'
so that it updates when moving etc...
-
Nov 25th, 2014, 05:44 PM
#6
Re: Game Screenshots
So, you're drawing on the form.
As stated, you can use Graphics.CopyFromScreen to copy the image of the form from the screen.
Or you could hit <Alt> <Print Screen> to capture the form to the clipboard and paste it into Paint, or something like that, and save it.
Or you could create a bitmap, get a Graphics object for that, and draw in the bitmap instead of the form.
i.e. instead of setting ScreenGraphics = Me.CreateGraphics, set ScreenGraphics = Graphics.FromImage(mybmp), then run through your drawing routine.
You need to create the bitmap and make it the same size as your form.
-
Nov 25th, 2014, 05:52 PM
#7
Re: Game Screenshots
By the way. The way you're drawing would tend to be more flashy, as you are erasing and drawing directly to the form's area of the screen.
It would be better to draw in the Form's paint event, with the form's doublebuffered property set to True so the drawing is done in the background and only shown once it is completed or do the drawing in a bitmap to begin with, and then draw the bitmap to the form in one shot, essentially manually doublebuffering.
Also, if you drew in a bitmap to manually doublebuffer, you would then just clone the bitmap whenever you wanted to take a snapshot at the end of a draw frame, no need to switch graphics objects and redraw to another bitmap.
-
Nov 25th, 2014, 05:52 PM
#8
Thread Starter
Junior Member
Re: Game Screenshots
Okay so if I change ScreenGraphics to
ScreenGraphics = Graphics.FromImage(mybmp)
when I run
ScreenGrahics.DrawImage()
Will it be visible?
or will i have to do something to draw the bitmap?
-
Nov 25th, 2014, 05:57 PM
#9
Thread Starter
Junior Member
Re: Game Screenshots
The way I am doing it is already a double buffer
at the end of each drawing cycle, I do this:
'COPY BACKBUFFER TO GRAPHICS OBJECTS
ScreenGraphics = Graphics.FromImage(Globals.BackBuffer)
'DRAW BACKBUFFER TO SCREEN
BackBufferGraphics = Gameplay.CreateGraphics
BackBufferGraphics.DrawImage(Globals.BackBuffer, 0, 0, 640, 640)
'FIX OVERDRAW
Globals.ScreenGraphics.Clear(Color.Black)
-
Nov 25th, 2014, 06:00 PM
#10
Thread Starter
Junior Member
Re: Game Screenshots
I knew that if I had a problem I could turn to VBforums!
It has worked!
I did it by adding the screenshot check before the 'wipe' happened!
When you said have it as ScreenGraphics = Graphics.FromImage()
That made me realise I have that....
IT WORKED!
Thank you so much for your help!
I am VERY appreciative
-
Nov 25th, 2014, 06:01 PM
#11
Re: Game Screenshots
<edit> You're posting fast. I'm responding to 3 posts back </edit>...
It wouldn't be visible, but it wouldn't need to be visible if you were just doing a "screenshot", and then resuming your normal drawing.
But, if you choose to draw into the bitmap all the time, then yes, once you've finished a frame, you would use the graphics object for the form to draw the bitmap on the form (assume you did a CreateGraphics for a variable called gForm.
gForm.DrawImage(mybmp, 0, 0)
-
Nov 25th, 2014, 06:04 PM
#12
Thread Starter
Junior Member
-
Nov 25th, 2014, 06:11 PM
#13
Re: Game Screenshots
Yes, your nomenclature ends up being a little confusing because
ScreenGraphics = Graphics.FromImage(Globals.BackBuffer)
is setting ScreenGraphics so that it draws in your BackBuffer (you're drawing in BackBuffer, not copying backbuffer to the screen).
and
BackBufferGraphics = Gameplay.CreateGraphics
is setting the BackBufferGraphics graphics object to draw on your form (I'm assuming Gameplay is the name of your form, but it could be a picturebox or anything else you can draw on), so the next statement (drawimage) is drawing to the screen.
So you use ScreenGraphics to drawn in the back buffer and BackBufferGraphics to draw to the screen.
You don't draw on a graphics object, you use a graphics object to draw on something.
-
Nov 25th, 2014, 06:13 PM
#14
Thread Starter
Junior Member
Re: Game Screenshots
Oh yeah, that makes a lot more sense!
Thank you for all of your help! This will help me out a lot in the future
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|