I'm trying to create an image entirely on memory (a plot from some data (floats)).
I managed to be able to retrieve an image from the internet and send it to an img tag via JSInterop. This seems to work nicely. This is the piece of code:
var Http = new HttpClient();
Stream imageStream = await Http.GetStreamAsync("https://avatars.githubusercontent.com/u/9141961");
var dotnetImageStream = new DotNetStreamReference(imageStream);
// those three lines should change to something like:
// Bitmap bmp = new Bitmap(100,100);
// bmp.setPixel(10,10, Color.FromARGB(200,0,0)
// var dotNetImageSteam = bmp.GetStream();
await JS.InvokeVoidAsync("setImage", "image", dotnetImageStream);
This works, what I don't find a way to do is to create a "Bitmap" or something similar where I can edit pixel values and then convert them to a similar stream that I can send to the JS method. I want that instead of the GetStreamAsync
My needs are simple, just RGB pixels and being able to set the width/height of the streamed image. Afterward, the HTML tag has another width/height, and I want the image to stretch to fill.
Any clues on what support class to use?
Note: if there is another way to print the image on the tag without going through JS I'm totally open to that
Note 2: I was able to create an image using ImageSharp Nuget, looking like that:
SixLabors.ImageSharp.Image Img = new SixLabors.ImageSharp.Image<Rgba32>(11,250);
using (SixLabors.ImageSharp.Image<Rgba32> image = new SixLabors.ImageSharp.Image<Rgba32>(400, 400))
{
image[200, 200] = Rgba32.ParseHex("#F00");
}
But now I don't know how to get a stream from this :)