Java Reference
In-Depth Information
but the most common hints deal with the edges. If only a single color is used for
the pixels of a curved shape, the edge will be jagged or aliased .Ananti-aliasing
algorithm adds pixels along the edges with graded transparency that gives the
edges a much smoother, continuous appearance. This process, however, takes
longer to calculate and so can be turned off if not needed:
g2.setRenderingHints (
new RenderingHints (RenderingHints.KEY - ANTIALISASING,
RenderingHints.VALUE - ANTIALIASING - OFF));
6.8.1.4 Transformation
Affine transformations are matrix operations on the 2D coordinates that keep par-
allel lines parallel. These transformations include translations, rotations, scaling,
and shearing. Such transformations can be made to individual shapes or to the
user space in general. A common technique is to move the origin to the center of
the component area:
double cx = getWidth () / 2.0;
double cy = getHeight () / 2.0;
g2.translate (cx, cy);
or
AffineTransform trans =
AffineTransform.getTranslateInstance (cx, cy);
g2.transform (trans);
6.8.1.5 Compositing
When a shape (see Section 6.8.2) such as rectangle is drawn over another shape,
then a compositing rule is used to decide how they are combined. The default
is that the source shape (the one currently being drawn) simply draws over
a destination shape (the one already drawn). However, with the java.awt.
AlphaComposite class you can choose from eight compositing rules such as
“destination-over” where the destination shape will be “on top” of the source
shape. The compositing formula also takes into account the transparency factors
of the source and destination shapes.
6.8.1.6 Clipping
Drawing can be restricted to just the area within a given shape's perimeter. This
masking can reduce the number of operations and thus speed up the drawing. This
can be particularly useful for animations where often only a part of the scene
changes from frame to frame.
Search WWH ::




Custom Search