Avoiding Low Memory Conditions when Image-Exporting Graphs |
| Applies to: yFiles for Java 2.9, 2.8, 2.7, 2.6, 2.5, 2.4, 2.3, 2.2, 2.1, 2.0 |
Categories this article belongs to:
| yFiles for Java | > yFiles Viewer | > Input and Output | > Exporting a Graph's Visual Representation |
Avoiding low memory conditions during image-exporting a graph can be done in either of two ways:
- Scaling the graph for the process using a scale factor smaller than 1.0, thus decreasing both width and height of the resulting image.
- Creating a set of image tiles where each one shows only part of the original image and thus only needs a fraction of the memory during the generation process.
Scaling the graph
Scaling the graph before generating the image can be done using the ViewPortConfigurator.setScalingFactor(double)
method when configuring the viewport, for example.
For more information on how to use class ViewPortConfigurator, see also this Knowledge Base article.
Image tiling
Image tiling, i.e., generating a number of small images instead of a single big one, substantially decreases the memory footprint during the generation process.
Class TiledImageOutputHandler
can be used as a thin wrapper around any of the classes for image export, e.g., GIFIOHandler
, or JPGIOHandler
.
The respective class is then used as a delegate that is invoked from within the tiling process.
The following sample code fragment shows one way class TiledImageOutputHandler can be used.
What the sample code does:
-
Takes an ImageOutputHandler
instance and two integral parameters for 'row' and 'column' that determine the number of tiles that will be generated.
- Optionally, the generated tiles are arranged in an HTML table (using the boolean parameter 'htmlTable').
-
For any invalid parameter values for 'row' or 'column' the given ImageOutputHandler
instance is simply returned.
public IOHandler getTilingWrapper(ImageOutputHandler ioh, int row, int column, boolean htmlTable) { // Check for valid parameter values. if (row < 1 || column < 1) { return ioh; } TiledImageOutputHandler tioh = new TiledImageOutputHandler(ioh); // Set the tiling accordingly. tioh.setRowCount(row); tioh.setColumnCount(column); // Set HTML table generation accordingly. tioh.setHTMLTableGenerationActive(htmlTable); return tioh; } |
| Keywords: | large - image - export - output - tiling - JPG - GIF - PNG - BMP - low - memory - tile - width - height - dimension - ViewPortConfigurator - TiledImageOutputHandler - row - column - HTML |


