# Export Diagram as an Image without an Open Diagram

Besides the diagram export functionality that is available as the export feature in the context menu of a diagram editor (or other diagram container), there is some generic support in Graphiti for exporting a diagram as an image file without having a diagram open; this functionality was introduced with Graphiti 0.13.0 as part of the Eclipse Neon release.

# Usage of the generic export

Graphiti provides in the IImageService a new method byte[] convertDiagramToBytes(Diagram diagram, int format) that can be used without having a diagram opened. The task of the tool implementation to be added on top of the framework offering is to load the diagram and store the returned binary data array in a file (or use it in any other appropriate way). That functionality can be triggered by any tool-defined means, e.g. from a context menu entry on the file in the Navigator.

The diagram export itself is totally independent from any currently opened diagram and does not even require a Graphiti tool being installed for the diagram type to export. However in case no diagram type provider for the diagram is found, a generic one is used; that means that for any images or platform graphics algorithms used inside that diagram the rendering cannot be correct. In such a case a dummy image respectively platform graphics algorithm (stating that the correct rendering is not available) will be used for rendering.

# Example

An example for triggering that functionality (including the loading of the diagram can be found the class SaveDiagramAsImageHandler, which is part of the org.eclipse.graphiti.examples.common plugin in ths SDK. It shows how to laod a Graphiti diagram resource from a file, extract the diagram from it and how to store the binary into an image file.