Getting Started with Java 2D - Two-dimensional drawing
(Page 2 of 4 )
Two-dimensional drawing is also called 2D drawing for short. It provides all the basic functionalities required for drawing two dimensional graphics. These functionalities include shapes, stroking, filling, color, alpha compositing, clipping, antialiasing, text, and transformations.
By definition, a shape in Java 2D is "an infinitely thin boundary which defines an inside and an outside in which pixels inside the shape are affected by the drawing operation, but those outside are not." In other words, anything defined using curves and lines that creates a boundary is a shape. Java 2D provides toolbox of standard shapes such as rectangles, arcs, and so forth.
Stroking is the process of drawing outlines of shapes with varying thickness and dotted lines. Using Java 2D this can be achieved very easily. By using the API one can define any dotted line pattern and specify how the corners and vertices of shapes are to be drawn.
While stroking deals with the boundary and outline of a shape, filling deals with space enclosed within the boundary or stroke that is the shape's interior. Using Java 2D, shapes can be filled using a solid color, pattern or gradient.
Displaying a color correctly depends mainly on the hardware. Hence it is one of the difficult aspects of computer graphics. Since Java is platform independent, the 2D API provides for a platform independent way of representing colors that does not depend on hardware or viewing conditions.
The process of adding new elements into the existing drawing is known as compositing. In normal drawing operations source destinations overwrite destination pixels, whereas in compositing both are produced in the final image. When compositing is done, if the pixels are being drawn as partially transparent, so that the destination pixels show through, then such compositing is known as alpha compositing. Java 2D provides alpha compositing through Porter-Duff rules which provide considerable flexibility in using compositing.
Limiting the area of the drawing operations is known as clipping. Using Java 2D API, any shape can be used for clipping.
Normally any drawing on the screen would have jagged edges. The technique of smoothing the edges of drawn images is termed antialiasing. Java 2D API takes care of the details of producing antialiased drawing.
Using 2D API, one can render strings, retrieve the shapes of individual strings or letters, and manipulate text in the same ways that shapes are manipulated. It can also use any of the True Type or Type1 fonts installed in client system.
Every object in Java 2D is subject to transformations. This means that any object can be translated, rotated, scaled and sheared as it is drawn.
Now let's look at the image processing functionalities provided by Java 2D.
Next: Image Processing >>
More Java Articles
More By A.P.Rajshekhar