Clipping the Drawing Region
by, 03-04-2012 at 05:49 PM (603 Views)
As a clipping path, shape object is used so that to restrict that drawing areas which will render. Clipping path is considered to be the portion of Graphic2D context. Call the Graphics2D.setClip & pass ahpe so that to set clip’s attributes. Clipping path gets shrink by clip method calling & then passing to other shape. A clip intersects to current shape and specified shape.
To set clip method pass the ellipse & call clip so that for setting the clip path for intersection of rectangle & ellipse.
Java Code:private Ellipse2D ellipse = new Ellipse2D.Float(); private Rectangle2D rect = new Rectangle2D.Float(); ... ellipse.setFrame(x, y, ew, eh); g2.setClip(ellipse); rect.setRect(x+5, y+5, ew-10, eh-10); g2.clip(rect);