From 7d4ba652ec873d17abdce3e6073dd4ad3955519b Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sat, 28 Feb 2026 21:56:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`SaveAsImage`=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E7=9A=84=E5=9B=BE=E7=89=87=E5=B0=BA=E5=AF=B8=E5=8F=98?= =?UTF-8?q?=E5=A4=A7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Internal/Utilities/ChartHelper.cs | 32 ++++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index abfebcc6..9b4f5b63 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -1398,10 +1398,34 @@ namespace XCharts.Runtime camera.Render(); RenderTexture.active = rt; - tex = new Texture2D(width, height, TextureFormat.ARGB32, false); - tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); - tex.Apply(); - ApplyRoundedCornerClip(tex, cornerRadii); + + // If exportScale > 1 we want to save the image back to the original logical + // size (option B): render at higher density, then downscale to target pixels + // so the saved image has original width/height but higher quality. + if (clampedExportScale > 1f) + { + var targetWidth = Mathf.Max(1, Mathf.CeilToInt(rectTransform.rect.width * scaleFactor)); + var targetHeight = Mathf.Max(1, Mathf.CeilToInt(rectTransform.rect.height * scaleFactor)); + + var smallRT = RenderTexture.GetTemporary(targetWidth, targetHeight, 0, rt.format); + Graphics.Blit(rt, smallRT); + + RenderTexture.active = smallRT; + tex = new Texture2D(targetWidth, targetHeight, TextureFormat.ARGB32, false); + tex.ReadPixels(new Rect(0, 0, targetWidth, targetHeight), 0, 0); + tex.Apply(); + RenderTexture.ReleaseTemporary(smallRT); + + var cornerRadiiFinal = GetChartCornerRadius(chart, rectTransform.rect.width, rectTransform.rect.height, scaleFactor); + ApplyRoundedCornerClip(tex, cornerRadiiFinal); + } + else + { + tex = new Texture2D(width, height, TextureFormat.ARGB32, false); + tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); + tex.Apply(); + ApplyRoundedCornerClip(tex, cornerRadii); + } } finally {