Getting Started > Rendering Images

Rendering Images

SharpPlot can generate the finished chart in any of five common vector formats (SVG, PDF, EPS, XAML, EMF, VML) and any raster image format supported by the .net Bitmap class (PNG, JPEG, BMP, GIF, TIF).

Vector vs Raster graphics

Raster graphics have a fixed resolution, so that the graphics are stored as a big matrix of monochrome cells – pixels – possibly with some compression. This forces the choice of a resolution (size in pixels of the whole image) at rendering time.

Vectorial graphics instead are stored as instructions to draw the graphics on an arbitrary XY plane. This means that they can be arbitrarily scaled on the output device. At rendering time, all you have to consider is how to scale it (Fixed size, Fixed Aspect, Stretch...)

In general, any vector format will be smaller (in byte count) than the corresponding raster image by a factor of between 5 and 10, excepted for charts which have a dense matrix of points, such as a contour plot with altitude shading, where the altitude shading is fundamentally a matrix of pixels.

Vectorial formats

  • SVG (Scalable Vector Graphic) is a ratified W3C standard and becoming the standard to vectorial graphics, supported by all modern web browsers – the latest to support it being Microsoft Internet Explorer version 9 (2011).
  • PDF (Portable Document Format) is a good format if you want to email a completed chart, or post several charts as a single document on your website. It might be a convenient way of packaging a large collection of graphs, with an appropriate navigation tree created by SharpPlot as bookmarks. It is the only format which works well with multiple pages.
  • EPS (Encapsulated PostScript). This is very suitable for including single charts in published documents prepared with high-end DTP software for printing on any PostScript device.
  • XAML (Extensible Application Markup Language) is the format created by Microsoft for (amongst other things) graphial definitions. This is the ideal format for integration into .net applications.
  • EMF (Enhanced Metafile). This is ideal for saving as a temporary format, and pasting into Word or PowerPoint.
  • VML (Vector Markup Language) was the vectorial graphics language designed by Microsoft for Internet Explorer 5. It is based on a W3C proposal (May 1998) but is unlikely to progress to a ratified open standard. VML is no longer supported by Microsoft and should not be used.

Raster formats

.Net supports the following raster formats : PNG, BMP, GIF, JPEG, TIF (see System.Drawing.Imaging.ImageFormat). These enumerations are passed as arguments to SaveImage and RenderBitmap functions which respectively save the completed chart on disk, and return it as a Bitmap object, which may for example be returned to the browser via http.

DPI setting

Most output functions takes the DPI (resolution in Dots Per Inch) to create the image at. To have the bounding box of the paper in pixels match the required height and width of the image in points, use 72 for the DPI setting (because there are 72 points per inch, and that SharpPlot use the point at its default unit).

Generally, for web publication, the default DPI setting of 96 – the pseudo-standard computer screen resolution – will be more appropriate. Remember to adjust the parameters in the image tag to match, if embedding the picture in a web page.

Here is an image tag suitable for a chart created with SharpPlot(432,324) and rendered with sp.RenderImage(96) to scale it up a little:

<img src="mychart.png" height=432 width=576 border=0 >

If you are creating charts to be printed at 300DPI, you should use RenderImage(300) which will generate a much larger picture, at the real size of the chart, in 72th of inches.

Multi-page documents

The Document class also offers the ability to aggregate multiple SharpPlot/SharpLeaf documents into a single one, possibly reordering the pages.

It also provides fine control over the output of multi-page document in formats that do not natively support multiple pages, such as

See also ...

Getting Started


Send comments on this topic
© Dyalog Ltd 2016