SharpPlot Reference > SharpPlot Methods > RenderBitmap Method

SharpPlot.RenderBitmap Method

Return completed chart rendered through raster engine.


bitmap cht = sp.RenderBitmap(72);

Return Value

The result of this call is a Bitmap object, rendered by default at 96dpi. Ths is may then be saved to disk in any of the common image formats, typically PNG or JPEG to benefit from image compression. GIF is not recommended for images with gradient fills as it is limited to 256 colours and is likely to show some banding.

For images to be used in printed material, you probably should use at least 300dpi to get acceptable quality.

The text will be anti-aliased by default, but you may over-ride the text-rendering algorithm by passing in the standard .Net rendering hint as a final option.

If your chart has made use of hyperlinks or JavaScript calls, you will need to create an accompanying image map, and include it in the completed webpage.



This script creates a simple chart and renders it for display in a web page:

<%@ page language="VB" AutoEventWireup="True"%>
<%@ Import Namespace = "System.Drawing" %>
<%@ Import Namespace = "System.Drawing.Imaging" %>
<%@ Import Namespace = "Causeway" %>

<Script Runat="Server">
  Sub Page_Load(sender as Object, e as EventArgs)
    Dim sp As Causeway.SharpPlot =  New Causeway.SharpPlot() 
    sp.DrawPieChart(New Integer(){34,23})
    Dim bitmap As Bitmap
    bitmap = sp.RenderBitmap()
    Dim stream As System.IO.MemoryStream
    stream = New System.IO.MemoryStream()
    bitmap.Save(stream, ImageFormat.Png)

    Response.ContentType = "image/png"    
  End Sub

Note the lines:

    Response.ContentType = "image/png"    

which set the correct type for the returned image and then return the rendered chart as a binary stream. To write the completed image to file, you could use:

   // Create a bitmap and save as PNG ...
    Bitmap chart = sp.RenderBitmap(72);
    Console.WriteLine("Image written to Simple.png at 72dpi");

See also ...

SharpPlot Members | SharpPlot.RenderImageMap Method | SharpPlot.SaveImage Method

Send comments on this topic
© Dyalog Ltd 2016