Clipping

The clipping path is a state attribute that specifies which part of a shape is to be rendered. In order to specify the clipping region, a path (see Listing 3.2 for the definition of a path) is created such that only the parts of the shape within the path are rendered. The clipping region can be specified by any valid Shape (for example, a GeneralPath or Rectangle2D). For example, a simple clipping path could be used in the myCustomRenderer class in our basic java graphics program recipe by adding the following:

 GeneralPath gp = new GeneralPath(); gp.moveTo((50,50); //initial starting point gp.lineTo(30,200); gp.lineTo(110,140); gp.lineTo(90,190); gp.lineTo(300,50); gp.closePath(); g2.setClip(gp); g2.setColor(new GradientPaint(); g2.fill(new ...

Get Java™ Media APIs: Cross-Platform Imaging, Media, and Visualization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.