[]
        
(Showing Draft Content)

Render to PNG

BitmapGraphicsRendering renders chart or diagram content to a raster image.

Renderer dimensions for raster and SVG output are specified in device-independent pixels based on 1/96 inch. The rectangle passed to Render is specified in points based on 1/72 inch. Use C1XLBook.TwipsToPixels to convert points to pixels:

float width = 450;
float height = 300;

int widthPx = C1XLBook.TwipsToPixels(20 * width);
int heightPx = C1XLBook.TwipsToPixels(20 * height);

The following example renders a FlexChart and converts the resulting PNG to a Base64-encoded string for embedding in HTML.

using System;
using System.IO;
using C1.Chart;
using C1.Chart.Standard;
using C1.Excel;
using C1.Util;

var chart = new FlexChart();
// Configure the chart.

float width = 450;
float height = 300;

int widthPx = C1XLBook.TwipsToPixels(20 * width);
int heightPx = C1XLBook.TwipsToPixels(20 * height);

string png;

using (var rendering = new BitmapGraphicsRendering(widthPx, heightPx))
{
    chart.Render(rendering, 0, 0, width, height);

    using (var stream = new MemoryStream())
    {
        rendering.Bitmap.SaveAsPng(stream);
        png = Convert.ToBase64String(stream.ToArray());
    }
}

Assign the Base64-encoded image to an HTML image data URI:

<img src="data:image/png;base64,[PNG DATA]">