piccolo2d / piccolo2d.java

Structured 2D Graphics Framework
http://piccolo2d.org
Other
51 stars 14 forks source link

Calling toImage() on a composite node often returns an empty image. #137

Closed mro closed 9 years ago

mro commented 9 years ago

Originally reported on Google Code with ID 137

Calling toImage() on a composite node often returns an empty image.

The problem looks like it is due to using getWidth() and getHeight()
instead of getFullBounds().getWidth() and getFullBounds().getHeight() in
PNode.toImage

A debugger session indicates that getWidth() is zero for composite nodes,
therefore, dividing by getWidth() is problematic.

Reported by reids%colorado.edu@gtempaccount.com on 2009-10-14 19:46:52

mro commented 9 years ago
Thank you for reporting this. I will resolve it shortly. (After putting in a unit
test to test it.)

Reported by allain.lalonde on 2009-10-14 20:10:11

mro commented 9 years ago
Failing test is: 
public void testToImageUsesFullBoundsWhenConvertingImage() throws IOException {
        node.setBounds(0, 0, 50, 50);
        PNode child1 = new PNode();
        child1.setBounds(0, 0, 100, 50);
        child1.setPaint(Color.RED);
        node.addChild(child1);

        PNode child2 = new PNode();
        child2.setBounds(0, 0, 50, 100);
        child2.setPaint(Color.BLUE);
        node.addChild(child2);

        BufferedImage image = (BufferedImage) node.toImage();
        assertNotNull(image);
        assertEquals(100, image.getWidth());
        assertEquals(100, image.getHeight());        
        assertEquals(Color.RED.getRGB(), image.getRGB(99, 1));
        assertEquals(Color.BLUE.getRGB(), image.getRGB(1, 99));
    }

Reported by allain.lalonde on 2009-10-14 20:36:42

mro commented 9 years ago
Fixed in r709

Reported by allain.lalonde on 2009-10-14 20:41:21

mro commented 9 years ago

Reported by heuermh on 2009-10-30 02:58:41