Hi all,

I have a weird problem which may be a bug, but hopefully has a solution. I am 
drawing a histogram whose bins are coloured according to an arbitrary colour 
map. This involves drawing a series of filled rectangles whose height is 
proportionally to the frequency of the bin, and then drawing an outline across 
the tops of these rectangles.

This works fine for colour maps with no transparency; however, when I want to 
apply transparency to the rectangles, they render incorrectly, and in a 
seemingly unpredictable way (see this image: 
http://www.typically.net/FTP/histogram_bug_all.png ).

The exact same code is used to render both instances, which is why I'm thinking 
this must be a Java2D bug... The rendering code (where g is the Graphics2D 
instance) is:

[code]
for (int i = 0; i < histogram.bins.size(); i++){
        boolean y_maxed = false;
        Histogram.Bin bin = histogram.bins.get(i);
        float x = x_start + ((float)i * bin_width);
        float _y = (float)bin.y * y_unit;
        if (_y > height){
                _y = height;
                y_maxed = true;
                }
        float y = y_start - _y;
        p.lineTo(x, y);
        //only outline top if it is not maxed
        if (y_maxed)
                p.moveTo(x + bin_width, y);
        else
                p.lineTo(x + bin_width, y);
        if (colour_model != null){
                double[] x_pixel = new double[]{bin.x};
                Color c = new Color(colour_model.getRed(x_pixel), 
                                        colour_model.getGreen(x_pixel),
                                        colour_model.getBlue(x_pixel),
                                        colour_model.getAlpha(x_pixel));
                                
                g2.setColor(c);
                Rectangle2D rect = new Rectangle2D.Float(x, y, bin_width, _y + 
1);
                g2.fill(rect);
                                
                //window line
                ...
                }
        }
[/code]
[Message sent by forum member 'typically' (typically)]

http://forums.java.net/jive/thread.jspa?messageID=338652

===========================================================================
To unsubscribe, send email to lists...@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
lists...@java.sun.com and include in the body of the message "help".

Reply via email to