- Home /
Screen capture with System.Drawing not working
I'm trying to create a screenshot of the entire screen, not just the window that Unity is running in, but currently the image file that is saved is just black.
Relevant code at the moment:
Bitmap screenGrab = new Bitmap(screenWidth, screenHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Graphics sG = System.Drawing.Graphics.FromImage(screenGrab);
sG.CopyFromScreen(screenWidth, screenHeight,0,0, screenGrab.Size, CopyPixelOperation.SourceCopy);
screenGrab.Save("TestScreen.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
It saves an image of the correct resolution, screenWidth and screenHeight are the correct size of my monitor, I've tried Save() with different filetypes, but I still just get a 100% black image. If it helps at all, I mainly followed this tutorial to create the script.
Answer by Tomas1856 · Feb 25, 2014 at 08:59 PM
I think the API - you're using will only work with Microsoft's .NET, if you're using this script inside Unity, this probably won't work, as Unity uses Mono inside.
Apparently some people have got it to work, I've had to drag the .dll into my project folder and set compatibility for .NET 2.0 and not .NET 2.0 subset, the issue just seems to be the capture of the screen.