Hi all,
I can generate images (png) however the issue I have is that the Molecule
is rendered too close to the boarder of the picture. It doesn't look nice
at all and sometimes something is cut-off.
The Code:
Rectangle drawArea = new Rectangle(width, height);
Image image = new BufferedImage(
width, height, BufferedImage.TYPE_INT_RGB);
if (generate2DCoordinates) {
StructureDiagramGenerator sdg = new StructureDiagramGenerator();
sdg.setMolecule(mol);
try {
sdg.generateCoordinates();
} catch (CDKException ex) {
logger.catching(ex);
}
mol = sdg.getMolecule();
}
GeometryTools.translateAllPositive(mol);
// generators make the image elements
ArrayList<IGenerator<IAtomContainer>> generators =
new ArrayList<IGenerator<IAtomContainer>>();
generators.add(new BasicBondGenerator());
generators.add(new BasicAtomGenerator());
generators.add(new BasicSceneGenerator());
// the renderer needs to have a toolkit-specific font manager
AtomContainerRenderer renderer =
new AtomContainerRenderer(generators, new AWTFontManager());
// the call to 'setup' only needs to be done on the first paint
renderer.setup(mol, drawArea);
// paint the background
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, width, height);
// the paint method also needs a toolkit-specific renderer
// this paint methods fits structure to available space
renderer.paint(mol, new AWTDrawVisitor(g2), drawArea, fitToImage);
Note that I tried fitToImage seems to have no effect at all. I trried to
pass the paint method a smaller rectangle or make drawArea smaller than the
Image. the later works but only for bottom and right edge, eg image is then
not centered.
Any ideas how to fix this?
Best Regards,
Joos
------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user