From 35b15311028e57f872936f34978839b5e5732232 Mon Sep 17 00:00:00 2001 From: Xam Date: Fri, 17 Apr 2026 23:08:33 +0000 Subject: [PATCH] HLE: CaptureManager: SaveScreenShot: properly handle screenshot image data (#18) no way this was working before, and if it did, just pure luck, unsafe blind copy of bytes as is and zero checks. i only tested tomodachi, but should fix all games that were crashing on saving screenshots the crash was happening because the screenshot buffer was bigger than the bitmap buffer, so marshall.copy() was raising an unhandhled expection crashing the emu. on top of this, because the data was just copied as is, the result image was garbled. [fixes #304](https://github.com/Ryubing/Issues/issues/304) Reviewed-on: https://git.ryujinx.app/projects/Ryubing/pulls/18 --- src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs b/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs index 3caea0f6c..f47c663ed 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs @@ -118,8 +118,11 @@ namespace Ryujinx.HLE.HOS.Services.Caps } // NOTE: The saved JPEG file doesn't have the limitation in the extra EXIF data. - using SKBitmap bitmap = new(new SKImageInfo(1280, 720, SKColorType.Rgba8888)); - Marshal.Copy(screenshotData, 0, bitmap.GetPixels(), screenshotData.Length); + using SKBitmap bitmap = new(new SKImageInfo(1280, 720, SKColorType.Rgba8888, SKAlphaType.Premul)); + int dataLen = screenshotData.Length > bitmap.ByteCount ? bitmap.ByteCount : screenshotData.Length; + + Marshal.Copy(screenshotData, 0, bitmap.GetPixels(), dataLen); + using SKData data = bitmap.Encode(SKEncodedImageFormat.Jpeg, 80); using FileStream file = File.OpenWrite(filePath); data.SaveTo(file);