0

For a basic personal interest project, I'm trying to make a C# winform which is a screen capture device, I want to be able to resize a transparent window, press a button on keyboard and the program save what it can see transparently through itself to a file.

All I need help with is a non-hacky way to get the image of what can be seen through the transparent window.

A quick mock up in ms paint: Mock up image

Any help would be appreciated.

Joshua
  • 293
  • 4
  • 19
  • like a magnifying glass – Jodrell Feb 28 '13 at 11:53
  • I didn't downvote, I like the idea of your app, but SO is a place for asking for help with specific problems. This seems more like asking somebody to design your system for you. What have you tried already? Where is your code? – Martin McGirk Feb 28 '13 at 11:54
  • Sounds like you want to do something kinda hacky in a non-hacky way :o. I don't know how to do this but you could try do a print screen and then just take the bit in the forms boundaries. This might help. http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/79efecc4-fa6d-4078-afe4-bb1379bb968b – James Feb 28 '13 at 11:55
  • @MartinMcGirk, downvotes are about the quality of the question not the idea behind it (or they should be) – Jodrell Feb 28 '13 at 11:59
  • @Jodrell, The quality of this question isn't as bad as its two downvotes would infer (in my unqualified opinion at least), a little effort was shown and the question was specific enough in its own way, I just wanted to distance myself from those downvotes. Maybe a period rather than a comma after "I didn't downvote" would have conveyed my meaning better. – Martin McGirk Feb 28 '13 at 12:08
  • Yes, like a magnifying glass, more like a window. The reason it seems ill-researched is because I'm going to be using a socket class I've made to send the picture to another computer over the internet, so you have a small window into another persons computer. I'll be using the project on the small team I'm working with on developing a 3D game so we can share where any animation rendering is up to without having to tell each other all the time. – Joshua Feb 28 '13 at 12:09

1 Answers1

6

Use Graphics.CopyFromScreen method:

using (Bitmap bmp = new Bitmap(width, height))
{
    using (Graphics g = Graphics.FromImage(bmp))
    {
        g.CopyFromScreen(x, y, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
    }

    // do whatever with `bmp`
}
Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72