Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
EloiStree opened this issue Dec 15, 2020 · 2 comments

Comments

@EloiStree
Copy link
Owner

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
Copy link
Owner Author

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;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant