Closed jtenney-alamar closed 2 months ago
Will check it out next week. :)
This issue is likely caused by the default settings of BlazorServer. I have mentioned it in the XML comment of the ToImage
method.
Please make sure to add the following to your Program.cs
:
builder.Services.AddServerSideBlazor().AddHubOptions(options => {
options.MaximumReceiveMessageSize = null; // no limit or specify a number
});
The ToImage
method returns the base64 string of the image with some prefix at the beginning.
You can use this output string directly in an image element or convert the returned string into a file using the following snippet:
var base64Image = await chart.ToImage(ImageFormat.Png, 512, 512);
var imageData = base64Image[(base64Image.IndexOf(",", StringComparison.Ordinal) + 1)..];
var imageBytes = Convert.FromBase64String(imageData);
await File.WriteAllBytesAsync("output.png", imageBytes);
This snippet removes the prefix from the base64 string and converts the remaining data into a PNG file named output.png
.
Simply never returns from ToImage() unless I leave Layout.Margin and Layout.Title as null.
However, it does work when I press the "Camera" to create an image.
Drawing a scatter plot with log-log X and Y axes.