Scaling in image rendering

User 4ceb4fe234

01-04-2008 11:17:06

Hi everybody,





just another question about image rendering. We are using MarvinBeans 5.0.0 to render molfiles to png.





The resulting images should have a fixed size (e.g. 200x200). Is there a possibility to set a maximum scale, i.e. when the calculated scaling factor is larger than the maximum scale the maximum scale should be used. Otherwise small molecules like benzene would be very large while other larger molecules containing a benzene ring somewhere would have very small benzene rings.





When I use the scale parameter, larger molecules may be cut at the edges of the images.





It would be very nice if I the scaling would be reduced automatically if the resulting images does not fit in the given dimensions.





Thanks in advance!





Helge

ChemAxon 7c2d26e5cf

01-04-2008 11:51:55

Please see the linking topic: Scaling in exported Image


The code sniplet in the mentioned topic demonstrates how you can play with the image dimension and scaling factor parameters.


Firstly, determine a max value for scaling. After then, calculate this factor for a fix image rect and compares the given value with the max one. If it is larger than the max scaling value, assign also the scale option (with the value of max scaling) to the parameter string of image export.

User 4ceb4fe234

01-04-2008 12:48:14

Hi Tamas,





I just tried the code and found that everything works as expected and desired!





Thanks for your fast response





Helge

ChemAxon 909aee4527

29-07-2008 07:33:01

Hi Helge,





maxscale is a new option for image scaling available from Marvin 5.0.7.


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





The codes below are equivalent:


Code:
        double scale =28; // required scaling factor


        String format = "jpeg:w600,h600";


        MolImageSize misize = mol.getImageSize(format); // calculate fitting-scaling factor





        // choose the better scalling factor


        if(misize.scale >= scale) {


            format += ",scale"+String.valueOf(scale);


        }


        byte[] data = mol.toBinFormat(format);








Code:
        String format = "jpeg:w600,h600,maxscale28";


        byte[] data = mol.toBinFormat(format);