From 59c57ad2cdeec99ba6698372b70c1a6482609b8e Mon Sep 17 00:00:00 2001 From: Gabriel A Date: Sat, 20 Jul 2024 12:13:37 -0300 Subject: [PATCH] Fix Skia saving screenshot with transparent background and incorrect origin --- src/Ryujinx/AppHost.cs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Ryujinx/AppHost.cs b/src/Ryujinx/AppHost.cs index 8c643f3402..30ba239408 100644 --- a/src/Ryujinx/AppHost.cs +++ b/src/Ryujinx/AppHost.cs @@ -367,29 +367,22 @@ namespace Ryujinx.Ava } var colorType = e.IsBgra ? SKColorType.Bgra8888 : SKColorType.Rgba8888; - using var bitmap = new SKBitmap(new SKImageInfo(e.Width, e.Height, colorType, SKAlphaType.Premul)); + using SKBitmap bitmap = new SKBitmap(new SKImageInfo(e.Width, e.Height, colorType, SKAlphaType.Premul)); Marshal.Copy(e.Data, 0, bitmap.GetPixels(), e.Data.Length); - SKBitmap bitmapToSave = null; + using SKBitmap bitmapToSave = new SKBitmap(bitmap.Width, bitmap.Height); + using SKCanvas canvas = new SKCanvas(bitmapToSave); - if (e.FlipX || e.FlipY) - { - bitmapToSave = new SKBitmap(bitmap.Width, bitmap.Height); + canvas.Clear(SKColors.Black); - using var canvas = new SKCanvas(bitmapToSave); + float scaleX = e.FlipX ? -1 : 1; + float scaleY = e.FlipY ? -1 : 1; - canvas.Clear(SKColors.Transparent); + var matrix = SKMatrix.CreateScale(scaleX, scaleY, bitmap.Width / 2f, bitmap.Height / 2f); - float scaleX = e.FlipX ? -1 : 1; - float scaleY = e.FlipY ? -1 : 1; - - var matrix = SKMatrix.CreateScale(scaleX, scaleY, bitmap.Width / 2f, bitmap.Height / 2f); - - canvas.SetMatrix(matrix); - - canvas.DrawBitmap(bitmap, new SKPoint(e.FlipX ? -bitmap.Width : 0, e.FlipY ? -bitmap.Height : 0)); - } + canvas.SetMatrix(matrix); + canvas.DrawBitmap(bitmap, SKPoint.Empty); SaveBitmapAsPng(bitmapToSave ?? bitmap, path); bitmapToSave?.Dispose();