Java 2D clip area to shape
Posted
by
user2923880
on Stack Overflow
See other posts from Stack Overflow
or by user2923880
Published on 2013-10-26T21:50:35Z
Indexed on
2013/10/26
21:53 UTC
Read the original article
Hit count: 267
I'm quite new to graphics in java and I'm trying to create a shape that clips to the bottom of another shape. Here is an example of what I'm trying to achieve:
Where the white line at the base of the shape is the sort of clipped within the round edges. The current way I am doing this is like so:
g2.setColor(gray);
Shape shape = getShape(); //round rectangle
g2.fill(shape);
Rectangle rect = new Rectangle(shape.getBounds().x, shape.getBounds().y, width, height - 3);
Area area = new Area(shape);
area.subtract(new Area(rect));
g2.setColor(white);
g2.fill(area);
I'm still experimenting with the clip methods but I can't seem to get it right. Is this current method ok (performance wise, since the component repaints quite often) or is there a more efficient way?
Thanks in advance.
© Stack Overflow or respective owner