Results 1 to 14 of 14

Thread: Game Screenshots

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    18

    Lightbulb 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

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    18

    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.

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Game Screenshots

    What are you calling a graphics object?
    Give an example of how you're drawing.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    18

    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...

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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.

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    18

    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?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    18

    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)

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    18

    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

  11. #11
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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)

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    18

    Re: Game Screenshots

    I understand what you mean, but instead of using the ScreenGraphics
    I used the backbuffer to do the screenshot.
    Which is basically the FINAL drawing of that frame and it worked!
    This is what it produced
    Name:  25_11_2014_23_0_50.jpg
Views: 345
Size:  74.2 KB

  13. #13
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    18

    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
  •  



Click Here to Expand Forum to Full Width