EloiStree / OpenMacroInput

When keyboard is not enough !!!
4 stars 1 forks source link

Topic: Capture the screen in C# to threat it in Unity but with the less possible preformance lost #46

Open EloiStree opened 3 years ago

EloiStree commented 3 years ago

I need to convert the screen(s) to Texture2D in unity to be able to make pixel condition and shadergraph filtering to improve the toolbox OMI. You can use the classic C# and user32 dll to copy the screen but it often crash and is very very slow 400-1000 milliseconds. I use also a java version that take 100-600 ms.

I need something more smooth. Because of performance but also because I would like to create my own virtual desktop version in Unity in an open source way in the future to make working environment.

So apparently they are ways of doing it. But that in skills I don't own. So let's learn new skills.

EloiStree commented 3 years ago

The main topic that send on large range of topic:

EloiStree commented 3 years ago

Using System.Drawing

 // Making fullscreen screenshot
    public static Bitmap makeScreenshot() 
    {
        Bitmap screenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);

            Graphics gfxScreenshot = Graphics.FromImage(screenshot);

            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

            gfxScreenshot.Dispose();

            return screenshot;
    }