Image of a diagram

Started by Hervé, April 26, 2017, 22:33:29 PM

Previous topic - Next topic

Hervé

Hi there,

Some people who use my database plugin asked me to add an option to export an image of the diagrams in the database. This way, they will be able to transfer them easily to other applications like web sites or other.

I do not like the way I did it : open the diagram, create an image from it using the DiagramUtils class, and then close the diagram.

I would like to find a way to create the images without showing up the diagrams on the screen. Do you know a way to achieve this ?

Thanks and regards
Hervé

Hervé

Ok, I've found a way to export generate views images without showing then.

For reference, here is the code I'm using :

public byte[] createImage(IDiagramModel view, double scale, int margin) throws IOException {
byte[] imageByteArray = null;
Image image = DiagramUtils.createImage(view, scale, margin);

ByteArrayOutputStream out = new ByteArrayOutputStream();
DataOutputStream writeOut = new DataOutputStream(out);
ImageLoader saver = new ImageLoader();
saver.data = new ImageData[] { image.getImageData() };
saver.save(writeOut, SWT.IMAGE_PNG);

imageByteArray =  out.toByteArray();

image.dispose();
writeOut.close();

return imageByteArray ;


The next release of my database plugin will be able to export an image of the views into the database  ;D

Best regards
Hervé