Is it possible to add a label to an Image?

User 6adcc60439

18-04-2012 00:44:46

I have been reading this documentation:


http://www.chemaxon.com/marvin/help/formats/images-doc.html


however, I would like to add the structure name to the image, is that possible?

ChemAxon a202a732bf

18-04-2012 07:50:24

Dear Jeff,


If you would like to add the name of the molecule to the image you can do it by adding a text box. The easiest way is to import the molecule in Marvin Sketch, add the text box and then save it as an image. It can be done by using the API too, below you can find a sample code that exports Benzene to png along with a text box containing its name.


Best regards,


Zsuzsa


    Molecule mol = MolImporter.importMol("C1=CC=CC=C1");
    Cleaner.clean(mol, 2, null);
    MDocument document = new MDocument(mol);
    DPoint3[] molCorners = mol.getEnclosingCube();
    double dist = 0.5;
    double height = 1.0;
    MPoint topLeft = new MPoint(molCorners[0].x,
        molCorners[0].y - dist, molCorners[0].z);
    MPoint bottomRight = new MPoint(molCorners[1].x,
        molCorners[0].y - dist - height, molCorners[1].z);
    MTextBox textBox = new MTextBox();
    textBox.setCorners(topLeft, bottomRight);
    textBox.setText("Benzene");
    textBox.setHorizontalAlignment(MTextBox.ALIGN_CENTER);
    document.addObject(textBox);
    MolExporter exporter = new MolExporter(
        new java.io.FileOutputStream("out/benzene.png"), "png");
    exporter.write(mol);
    exporter.close();