0

I know how to capture the screen using C#, but I want to capture a screenshot of specific window, not a part of the screen. If it possible with C# .NET?

Edit:

When I capture a window like this:

The result will be like this:

But when I capture a window like this:

I still want the result like:

Not:

How can I do that in C# .NET?

Higg Higg
  • 79
  • 8
  • 4
    Yes, it is possible. What do you mean by "capture" – Caius Jard Dec 28 '21 at 09:24
  • https://www.c-sharpcorner.com/UploadFile/2d2d83/how-to-capture-a-screen-using-C-Sharp/ There is a solution here. –  Dec 28 '21 at 09:30
  • There are plenty of duplicates for this; what have you tried? – Caius Jard Dec 28 '21 at 09:30
  • @MuhammedYILMAZ I don't want to capture a screen or a part of the user screen, I want to capture a screen of a window – Higg Higg Dec 28 '21 at 09:32
  • 1
    For example: https://stackoverflow.com/questions/1163761/capture-screenshot-of-active-window has an answer from Ivan that captures a particular window (the active one); you just need to get some other code that finds the window handle of what you want to capture if it's not the active one – Caius Jard Dec 28 '21 at 09:34
  • @HiggHigg "I know how to capture the screen using C#, but I want to capture a screenshot of specific window," So you did not explain your self exactly. What is a window. What is a screen? Give us example. –  Dec 28 '21 at 09:51
  • @MuhammedYILMAZ I add some example. – Higg Higg Dec 29 '21 at 01:52
  • @HiggHigg so if i understand clearly, you want to capture a window of a program? –  Dec 29 '21 at 02:06
  • @MuhammedYILMAZ Yes, something like that! – Higg Higg Dec 29 '21 at 02:44

1 Answers1

0

If it is a game window, usually you need 3rd party library to inject into video stream (Direct3d, OpenGL, etc). But I doubt it will be possible to capture screen in foreground, you still need to make it active. Like this:

Capture screenshot of fullscreen DX11 program using SharpDX and EasyHook

C# Which is the fastest way to take a screen shot?

If it is simple windows application, it is much simplier. This work in foreground too:

Capture screenshot of active window?

eocron
  • 6,885
  • 1
  • 21
  • 50
  • 2
    This isn't how stackoverflow works. First we use comments to determine what the problem is, then if it's a duplicate we close the question as a duplicate. We do not provide answers that have lists of links ot other answers with a "if elseif elseif... block" – Caius Jard Dec 28 '21 at 09:32
  • 1
    I provide answer sufficient for his problem. The problem is not simply "use this function". It is if/elseif because world is not perfect, and one approach not work with another. I myself spent 4 hours to understand why I need Direct3D (looking into game folder) and what difference between GDI and other windows features. In separate questions. Like OP did. Don't tell me that this is some kind of stackoverflow feature to provide part of the answer in different questions. – eocron Dec 28 '21 at 09:36
  • 1
    Yea, that seems picky. This answer is just fine. It just covers multiple variants.. – Jakoss Dec 28 '21 at 09:38
  • So I need to use some stuff like Tao or OpenTK to do this? – Higg Higg Dec 28 '21 at 09:39
  • Yes, if they provide feature to inject into video stream. In examples above Direct3d has such feature and it was possible to fetch those image bytes. – eocron Dec 28 '21 at 09:40