0

I am wanting to turn the example below in a figure that uses RoundedRectangles instead of normal rectangles, I know there are possibilities with the clipping frame. But I don't really know how they would apply to my current situation, as I am not using a g2d.fillXXX() function currently.

The image: example http://img827.imageshack.us/img827/6048/cardbackgroundcut.jpg

The code:

private void createImage() {
    bufferedImage = new BufferedImage(dimension.width, dimension.height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = (Graphics2D)bufferedImage.createGraphics();

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    int colorRed = 128;
    int colorGreen = 0;
    int colorBlue = 128;

    for (int x = 0; x < dimension.width; x++) {
        for (int y = 0; y < dimension.height; y++) {
            int dx = Math.min(x, dimension.width - x);
            int dy = Math.min(y, dimension.height - y);
            if (dx < 10 || dy < 10) {
                g2d.setColor(new Color(colorRed, colorGreen, colorBlue, 255 - Math.min(dx, dy)));
                g2d.drawLine(x, y, x, y);
            }
            else {
                g2d.setColor(new Color(colorRed, colorGreen, colorBlue, 192 - Math.min(dx, dy)));
                g2d.drawLine(x, y, x, y);
            }
        }
    }
}

So basically I would want both the outer edge and the inner edge of the image have a rounded rectangle, while preversing the changes in color.

Any clues how to accomplish this?

Regards.

skiwi
  • 66,971
  • 31
  • 131
  • 216

1 Answers1

1

you can use a RoundRectangle and 4 (turned) rectangles cast all the shape to Area's to and use the

area.exclusiveOr(ohterArea)

method to get the 4 separate (different gradient) parts. And then draw these parts 1 by 1 using the GradientPaint class to paint (fill) all these 4 parts to the desired gradient.

and as a last step you set the paint back to a static color and you draw the old RoundedRectangle (so you get the edge)

Daan Luttik
  • 2,781
  • 2
  • 24
  • 37