Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Taking screenshot from a DX game

Taking screenshot from a DX game

Scheduled Pinned Locked Moved C#
graphicsgame-devhelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SimpleData
    wrote on last edited by
    #1

    Hi Maybe this is the second or third time I'm asking this question here and other programming platforms, yet I still don't have a satisfacting solution/answer. I would like to be able to get screenshots from a DX game without any black/blank screenshot or desktop views_(game is on foreground but desktop is saved in screenshot)_. Currently I am using this code to take screenshots, which works most of the time. On XP if anti-aliasing is enabled in game I sometimes get black screenshots. On Vista I sometimes get black screenshots. On 7 if aero is not disabled I get black screenshots all the time or desktop views.

    int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
    int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
    Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
    Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
    gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
    bmpScreenShot.Save("test.jpg", ImageFormat.Jpeg);

    I need to take screenshots without these problems without using SlimDX (and other external libraries needed to be installed). But an external DLL is OK. Thank you. I hope I can solve this with your help.

    D 1 Reply Last reply
    0
    • S SimpleData

      Hi Maybe this is the second or third time I'm asking this question here and other programming platforms, yet I still don't have a satisfacting solution/answer. I would like to be able to get screenshots from a DX game without any black/blank screenshot or desktop views_(game is on foreground but desktop is saved in screenshot)_. Currently I am using this code to take screenshots, which works most of the time. On XP if anti-aliasing is enabled in game I sometimes get black screenshots. On Vista I sometimes get black screenshots. On 7 if aero is not disabled I get black screenshots all the time or desktop views.

      int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
      int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
      Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
      Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
      gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
      bmpScreenShot.Save("test.jpg", ImageFormat.Jpeg);

      I need to take screenshots without these problems without using SlimDX (and other external libraries needed to be installed). But an external DLL is OK. Thank you. I hope I can solve this with your help.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      SimpleData wrote:

      without using SlimDX (and other external libraries needed to be installed). But an external DLL is OK.

      This is a contradictory statement. Each of these libraries IS an external .DLL. So, which is it?? Use an external library or not?? If not, they you've pretty much hung yourself. The reason why you're getting black screens is because you're using GDI+ to grab the screenshot. DirectX doesn't use GDI at all to draw it's graphics, so that's why you get black screens. You're taking a snapshot of the display buffer Windows maintains, but DirectX does draw to this buffer. It draws directly to the video frame buffer, bypassing Windows and GDI.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        SimpleData wrote:

        without using SlimDX (and other external libraries needed to be installed). But an external DLL is OK.

        This is a contradictory statement. Each of these libraries IS an external .DLL. So, which is it?? Use an external library or not?? If not, they you've pretty much hung yourself. The reason why you're getting black screens is because you're using GDI+ to grab the screenshot. DirectX doesn't use GDI at all to draw it's graphics, so that's why you get black screens. You're taking a snapshot of the display buffer Windows maintains, but DirectX does draw to this buffer. It draws directly to the video frame buffer, bypassing Windows and GDI.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008
        But no longer in 2009...

        S Offline
        S Offline
        SimpleData
        wrote on last edited by
        #3

        What I meant by that statement was actually this: as far as I know SlimDX needs to be installed to the user's pc as a package. But using one or two extra dll is acceptable. Thank you for explaining why I get black screenshots, but your answer brings another question, why do I get normal successful screenshots sometimes? How can I directly read from DX's buffer? I get the handle of the game I want to capture from and set it as a device but C# doesn't let me read the buffer of another application because .NET wants to protect inter-application boundries I guess.

        D 1 Reply Last reply
        0
        • S SimpleData

          What I meant by that statement was actually this: as far as I know SlimDX needs to be installed to the user's pc as a package. But using one or two extra dll is acceptable. Thank you for explaining why I get black screenshots, but your answer brings another question, why do I get normal successful screenshots sometimes? How can I directly read from DX's buffer? I get the handle of the game I want to capture from and set it as a device but C# doesn't let me read the buffer of another application because .NET wants to protect inter-application boundries I guess.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          SimpleData wrote:

          How can I directly read from DX's buffer?

          No idea, I've never done such a thing. Every game I'm ever wanted a screen shot of always had it's own facility to do so.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups