0

I am using the below code that will take screenshot of my desktop and it is running fine on my local machine but as soon as i upload the file in the server it is not taking the screen shot and throwing a error.

Error: The handle is invalid

System.ComponentModel.Win32Exception (0x80004005): The handle is invalid at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation) at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize) at Main.Capture(String CapturedFilePath) System.ComponentModel.Win32Exception (0x80004005): The handle is invalid at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation) at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize) at Main.Capture(String CapturedFilePath) System.ComponentModel.Win32Exception (0x80004005): The handle is invalid at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation) at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize) at Main.Capture(String CapturedFilePath)

My Asp.net Code behind code is as follows:

Bitmap bitmap = new Bitmap(2700, 800);
Graphics graphics = Graphics.FromImage(bitmap as  System.Drawing.Image);
graphics.CopyFromScreen(25, 25, 25, 25, bitmap.Size);
using (MemoryStream ms = new MemoryStream())
{
    //  bitmap.Save(@"d:\\Screen", ImageFormat.Jpeg);
    bitmap.Save(ms, ImageFormat.Jpeg);
    Ret = ms.ToArray();
}
शेखर
  • 17,412
  • 13
  • 61
  • 117
Satyam Gupta
  • 51
  • 1
  • 6
  • You can refer [this question](http://stackoverflow.com/questions/6887183/how-to-take-screen-shot-of-a-div-with-javascript) – शेखर Sep 23 '15 at 04:56

1 Answers1

4

What are you trying to achieve? If you want to take screenshot of user's desktop - it is not possible from C# (i.e. server side).

If you are trying to take a screenshot of a server - it kinda makes no sense. It doesn't work for you since there could be no desktop at all on the server: ASP.NET is hosted by IIS which is logged in as a service and thus doesn't have access to server's desktop.

torvin
  • 6,515
  • 1
  • 37
  • 52