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

Take screenshot #45

Open
merco opened this issue Oct 11, 2024 · 2 comments
Open

Take screenshot #45

merco opened this issue Oct 11, 2024 · 2 comments

Comments

@merco
Copy link

merco commented Oct 11, 2024

how can it be possible to have a screenshot of the displayed image?

maybe even offscreen?

@hjoykim
Copy link
Owner

hjoykim commented Oct 12, 2024

hello,

I'm not sure what screen you want to capture, but if you want to capture the rendered screen, you can do so using the code below.

private unsafe void CopyScreenToTexture_And_SaveToFile(string fileName)
{
    int size = renderer.Width * renderer.Height*4;
    
    byte[] buffers = new byte[size];
    fixed (byte* p = buffers) {
        GL.ReadPixels(0, 0, renderer.Width, renderer.Height, All.BgraImg, All.UnsignedByte, (IntPtr)p);
    }
    SKBitmap bitmap = new SKBitmap(renderer.Width, renderer.Height);
    using (var image = SKImage.FromBitmap(buffers.ToSKBitMap(renderer.Width, renderer.Height)))
    using (var data = image.Encode(SKEncodedImageFormat.Jpeg, 100))
    using (var stream = File.OpenWrite("screencapture.jpg"))
    {
        data.SaveTo(stream);
    }
}

@merco
Copy link
Author

merco commented Oct 12, 2024

@hjoykim

Is there a mirror?

immagine

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

2 participants