Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
System.Windows.Forms package is not supported in MVC. Apart from that, while doing R&D I learned about different screenshot Nuget packages but I am not sure how to use them.

What I have tried:

C#
using System.Windows.Forms; 
using Point = System.Drawing.Point;
using Rectangle = System.Drawing.Rectangle;
Rectangle bounds = Screen.GetBounds(Point.Empty);

using(Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
    using(Graphics g = Graphics.FromImage(bitmap))
    {
         g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
    }
    // will save to working directory  ( for C# WPF in VS 2019: C:\Users\{user}\source\repos\{project}\{project}\bin\Debug )
    bitmap.Save("test.jpg", ImageFormat.Jpeg);
}

C#
private Bitmap GetSreenshot()
{
  Bitmap bm = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
  Graphics g = Graphics.FromImage(bm);
  g.CopyFromScreen(0, 0, 0, 0, bm.Size);
  return bm;
}
Posted
Updated 12-Jul-22 7:10am
v2

Your code is running on the server.

Even if you did manage to get it working, all you would capture would be a screenshot of the server's screen. Which would most likely be sat at the lock screen or login prompt, since you don't normally leave servers logged in.

If you want to capture all or part of the user's screen, you'll have to use Javascript:
Using the Screen Capture API - Web APIs | MDN[^]

And before you ask: no, there is no way around the prompt for permission, and there is no way to force the user to grant you permission. If there were, it would be a massive security vulnerability.

Edit: As I told you last time you asked this exact question[^].

Posting the same question over and over again is not going to change the answer. And it will potentially get you kicked off the site.
 
Share this answer
 
v2
You can't.

Any C# code you write will ALWAYS run on the server and capture a screen shot of the service desktop, which will be blank.

You cannot capture a screen shot of a client using code that will only run on the server.

You MUST use javascript to do it, and, like Richard already said, you cannot do it without the user knowing and giving permission to do so.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900