-
Hello! I'm trying to have something like I have viewed #992, but I tried to do that like this: public static Image AsImage(this IEnumerable<Plot> plots,
int columnCount, int plotWidth, int plotHeight)
{
var plotsArray = plots.ToArray();
var height = (plotsArray.Length + columnCount - 1) / columnCount * plotHeight;
var width = plotWidth * columnCount;
using SKSurface surface = SKSurface.Create(new SKImageInfo(width, height));
var left = 0;
var top = 0;
foreach (var plot in plots)
{
var right = left + plotWidth;
var bottom = top + plotHeight;
plot.Render(surface.Canvas, new PixelRect(left, right, bottom, top));
if (right == width)
{
left = 0;
top = bottom;
}
else
{
left = right;
}
}
return new Image(surface);
} But it only keeps the last plot, while the rest part of the image seems to be cleared. So is there a simple solution to that? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Oh I just realized that ScottPlot relies on SkiaSharp. I can use it without any burden now. public static SKBitmap ToSKBitmap(this IEnumerable<Plot> plots,
int columnCount, int plotWidth, int plotHeight)
{
var plotsArray = plots.ToArray();
var height = (plotsArray.Length + columnCount - 1) / columnCount * plotHeight;
var width = plotWidth * columnCount;
var bitmap = new SKBitmap(width, height);
using var canvas = new SKCanvas(bitmap);
var left = 0;
var top = 0;
foreach (var plot in plots)
{
using SKSurface surface = SKSurface.Create(new SKImageInfo(plotWidth, plotHeight));
plot.Render(surface.Canvas, plotWidth, plotHeight);
canvas.DrawSurface(surface, left, top);
left += plotWidth;
if (left == width)
{
left = 0;
top += plotHeight;
}
}
return bitmap;
} (P.S. In my case, |
Beta Was this translation helpful? Give feedback.
Oh I just realized that ScottPlot relies on SkiaSharp. I can use it without any burden now.