| ||
Introducing SharpPlot Your First Chart Recent Updates Sample Charts Tutorials General Tutorials Chart Tutorials SharpPlot Class Properties Structures Enumerations Style examples Glossaries Active Charts VectorMath Class DBUtil Class Get SharpPlot Download SharpPlot Buying SharpPlot SharpPlot Support Upgrading from GraPL Release notes |
Reference > Methods > RenderBitmap Method SharpPlot.RenderBitmap MethodReturn completed chart rendered through raster engine. Examplebitmap cht = sp.RenderBitmap(72); cht.Save("cht.png",System.Drawing.Imaging.ImageFormat.Png); Return ValueThe 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. 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 imagemap, and include it in the completed webpage. Overloads
ExampleThis 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.Clear() Response.ClearHeaders() Response.ContentType = "image/png" Response.BinaryWrite(stream.ToArray()) Response.End() End Sub </Script> Note the lines: Response.ContentType = "image/png" Response.BinaryWrite(stream.ToArray()) 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); chart.Save("Simple.png",System.Drawing.Imaging.ImageFormat.Png); Console.WriteLine("Image written to Simple.png at 72dpi"); For images to be used in printed material, you probably should use at least 300dpi to get acceptable quality. See also ...SharpPlot Members | RenderImageMap Method | SaveImage Method |