feat: add JPEG support to /api/chart/v2 (?format=jpg|jpeg)

This commit is contained in:
2026-05-27 18:06:34 +02:00
parent 9ac3610064
commit f9a7d7a8d2
2 changed files with 17 additions and 6 deletions

View File

@@ -42,7 +42,7 @@ public static class SkiaChartRendererV2
// Entry point
// ═══════════════════════════════════════════════════════════════════
public static byte[] RenderToPng(ChartDataV2 data, int width = 1100, int height = 700)
public static byte[] RenderToPng(ChartDataV2 data, int width = 1100, int height = 700, bool jpeg = false)
{
using var surface = SKSurface.Create(new SKImageInfo(width, height));
var canvas = surface.Canvas;
@@ -164,8 +164,10 @@ public static class SkiaChartRendererV2
DrawLegendBottom(canvas, plotArea, allLegend, width);
using var image = surface.Snapshot();
using var pngData = image.Encode(SKEncodedImageFormat.Png, 95);
return pngData.ToArray();
using var imgData = jpeg
? image.Encode(SKEncodedImageFormat.Jpeg, 90)
: image.Encode(SKEncodedImageFormat.Png, 95);
return imgData.ToArray();
}
// ═══════════════════════════════════════════════════════════════════