I am using TexturePaint to fill polygon's with very basic
1bit patterns (diagonal, horizontal and vertical lines, and
combinations thereof, generalised code to generate TexturePaint
below).

The bitmap image does not change but the colour and
possibly the transparency can change quite frequently.

Is there a more efficient way to fill a polygon with
a single coloured bitmap, when the bitmap colour changes?

If not is there any limit on the number of TexturePaint's
that I can create and cache?

Regards,
Damian



    private TexturePaint createPixmap(Color colour, byte bits[], int width,
int height) {
        BufferedImage bi = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
        WritableRaster r = bi.getRaster();

        int num = r.getNumBands();
        if (num == 4) {
            int samples[] = new int[4];

            for (int row = 0; row < height; ++row) {
                int line = bits[row];
                for (int col = 0; col < width; ++col, line >>= 1) {
                    int val = (line & 1);
                    samples[0] = val == 0 ? 0 : colour.getRed();
                    samples[1] = val == 0 ? 0 : colour.getGreen();
                    samples[2] = val == 0 ? 0 : colour.getBlue();
                    samples[3] = val == 0 ? 0 : colour.getAlpha();

                    r.setPixel(col, row, samples);
                }
            }
        } else {
                // handle number of bands being wrg... should never happen.
        }

        Rectangle rect = new Rectangle(0, 0, width, height);
        return new TexturePaint(bi, rect);
    }

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to