Free Support Forum - aspose.com

Rendering PNGs in memory

Hi there,

Is there any way I can render PNG images from a map in memory?

Currently I’m rendering the PNG to a file path, then loading that image into a memory stream in order to get the image bytes, then removing that image using the same file path.

Is there a more efficient way of doing this?

image.png (5.1 KB)

Hi, @kmochrie

Well, of course. Please consider the below code.

    using (var stream = new MemoryStream())
    {
        // render in stream
        var path = AbstractPath.FromStream(stream);
        map.Render(path, Renderers.Png);

        // convert in base64 string.
        var byteArray = stream.ToArray();
        var bytes = Convert.ToBase64String(byteArray);
    } 

Thanks.

That’s exactly what I was looking for, thank you!

@kmochrie,

You are welcome.