feat: add JPEG support to /api/chart/v2 (?format=jpg|jpeg)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user