- Home /
Question by
ValentinBeaule · Oct 09, 2020 at 08:24 AM ·
screenshotprocess
Capture screen of external process
Hello,
I've got this code:
public void Launch()
{
Process process = Process.Start("mspaint.exe");
Thread.Sleep(1000);
User32.GetWindowRect(process.MainWindowHandle, out User32.RECT rect);
Tools.ScreenCapture screenCapture = new Tools.ScreenCapture();
Bitmap img = screenCapture.CaptureWindow(process.Handle);
img.Save("c:\\tmp\\test.png", ImageFormat.Png);
//gameObject.GetComponent<Image>
}
It's supposed to work but I always get an empty "MainWindowHandle" (0x0) which is supposed to be define as the application is graphical. The code works outside Unity, with a in independent project. When I try Process.GetCurrentProcess(), I always get Unity which may be why it doesn't work.
I don't mind using an other method. All I want is to capture a screenshot of an external application and a crossplateforme solution.
Thank you for your help.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613013415im_/https://answers.unity.com/themes/thub/images/avi.jpg)