#1129 AtomContainerRenderer.paint() returns negative values rect

jchempaint-primary
closed
nobody
5
2012-11-14
2011-04-19
No

The code extract:

=== code ===
Graphics2D graphics = image.createGraphics();
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, image.getWidth(), image.getHeight());

chemicalMoleculeRenderer.setup(molecule, new Rectangle(image.getWidth(), image.getHeight()));
Rectangle imageRect = chemicalMoleculeRenderer.paint(molecule, new AWTDrawVisitor(graphics));

image.getSubimage(imageRect.x, imageRect.y, imageRect.width, imageRect.height);
=== /code ===

generates the following rect: java.awt.Rectangle[x=-6,y=96,width=512,height=408]
which causes the following exception:

Caused by: java.awt.image.RasterFormatException: x lies outside raster
at sun.awt.image.IntegerInterleavedRaster.createWritableChild(IntegerInterleavedRaster.java:444)
at java.awt.image.BufferedImage.getSubimage(BufferedImage.java:1156)

Expected: AtomContainerRenderer.paint() always returns a valid rect, which is inside the rect passed to AtomContainerRenderer.setup().

Discussion

  • Dmitry Katsubo

    Dmitry Katsubo - 2011-04-19

    The sample molecule, that caueses the problem

     
  • Ralf Stephan

    Ralf Stephan - 2012-11-14

    Not confirmed with recent JCP/CDK combo. Can you please give the JCP/CDK versions you're using, and try again with the newest?

     
  • Dmitry Katsubo

    Dmitry Katsubo - 2012-11-14

    If it works with attached MOL, the issue can be closed. Sorry, I can't re-test it.

     
  • John May

    John May - 2012-11-14

    Yep it is working okay:
    java.awt.Rectangle[x=141,y=190,width=49,height=36]

    As a reference - if you just want to draw a container to given size (inferred from the subimage) you can do this:

    int h = 512; // 256, 756, 1028 are all good scales
    int w = (int) ( h * 1.618d ); // golden ratio
    
    BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = img.createGraphics();
    g2.setBackground(Color.WHITE); // or another colour
    Rectangle2D bounds = new Rectangle2D.Double(0, 0, w, h);
    g2.fill(bounds); // fills with white
    renderer.paint(container, new AWTDrawVisitor(g2), bounds, true);
    g2.dispose();
    
     
    Last edit: John May 2012-11-14
  • John May

    John May - 2012-11-14
    • status: open --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks