Have one to sell? Sell yours here
or
Get a £0.25 Amazon.co.uk Gift Card
Java 2D Graphics (Java Series)
 
 
Tell the Publisher!
I’d like to read this book on Kindle

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Java 2D Graphics (Java Series) [Paperback]

Jonathan Knudsen
3.0 out of 5 stars  See all reviews (4 customer reviews)

Available from these sellers.


‹  Return to Product Overview

Product Description

Amazon.co.uk Review

Java 2D Graphics is a remarkably accessible guide to graphics programming using Sun's new Java 2D API. Besides the basic navigation of the API, this title delivers plenty of useful advanced material for extending Java 2D's capabilities.

After a simple introductory example, the book focuses on the graphics architecture of Java 2D and its rendering pipeline. Support classes in Java 2D receive ample coverage as well, with sections outlining topics such as storing points, shapes and paths. For basic graphics output, the book demonstrates simple tasks--the process of drawing common shapes such as lines, ellipses, and rectangles--as well as the complex as seen when modifying graphics output through translating, rescaling, rotating or shearing.

Text output in Java 2D receives its due as well, since the book acknowledges Java 2D's advanced font capabilities that allow it to handle right-to-left languages such as Arabic. Further sections delve into Java 2D colour models (including support for the CIEXYZ and sRGB colour standards). With regard to the display of images, the book covers the built-in support for image filtering in Java 2D which allows programmers to build toggles and fades into their code that alter brightness, contrast, blurring and sharpening.

For advanced readers, Java 2D Graphics presents techniques like double buffering and matrix operations for custom image effects. Another expert section, on the internal storage classes for image data, will be useful for those who want to write image decoders. (A sample PNG decoder demonstrates the basics here.) Final sections look at printing, animation and performance issues.

In all, Java 2D Graphics provides a fine introduction to the latest in 2-D graphics programming from Sun, in a title that will be useful to both beginning and advanced Java developers. --Richard Dragan, Amazon.com

Product Description

One weakness of Java has been its graphics capabilities. Java 1.0 and 1.1 only included simple primitives for line drawing: lines could only be one pixel wide, they could only be solid, and there wasn't any good way to draw curves. Font management and color management were also weak. Java 2D (collectively called the "2D API") signals a major improvement in Java's graphics capabilities. It covers many of the classes in Java 1.2 that address graphics handling and improves on many weaknesses that were present in the previous versions of Java.

The 2D API allows you to produce high-quality, professional images on a screen or printer. Java 2D Graphics describes the 2D API from top to bottom, demonstrating how to set line styles and pattern fills as well as more advanced techniques of image processing and font handling. You'll see how to create and manipulate the three types of graphics objects: shapes, text, and images. Other topics include image data storage, color management, font glyphs, and printing.

Java 2D Graphics assumes no prior knowledge of graphics. Chock full of detailed explanations and examples, this book provides beginning Java programmers with a solid foundation in 2D graphics and helps more advanced programmers create and use high-quality images in their applications.

Topics covered in the book include:

  • The rendering pipeline
  • Shapes and paths
  • Geometry
  • Painting with solid colors, gradients, and textures
  • Stroking paths, including dashed lines
  • Transformations: translation, rotation, shearing, and scaling
  • Alpha compositing
  • Clipping
  • Rasterizing and antialiasing
  • Fonts and text
  • Font metrics
  • Glyphs
  • Colors and color spaces
  • sRGB and CIEXYZ
  • ICC color profiles
  • Images, image color models, and image data
  • Image processing
  • Image data storage
  • Graphics devices
  • Printing

From the Publisher

Java 2D Graphics describes the 2D API from top to bottom, demonstrating how to set line styles and pattern fills as well as more advanced techniques of image processing and font handling. You'll see how to create and manipulate the three types of graphics objects: shapes, text, and images. Other topics include image data storage, color management, font glyphs, and printing.

About the Author

Jonathan Knudsen is an author at O'Reilly & Associates. His books include The Unofficial Guide to Lego Mindstorms Robots, Java 2D Graphics, and Java Cryptography. He is the Courseware Writer for LearningPatterns.com.

Excerpted from Java 2D Graphics by Jonathan Knudsen. Copyright © 1999. Reprinted by permission. All rights reserved.

Chapter 4 - Painting and Stroking
In this chapter:
Painting
Stroking
Overlap

In the last chapter, we saw how shapes are defined in the 2D API. But what can you do with shapes?
Painting is the process of filling the interior of the shape with a color, color gradient, or texture.
Stroking is the process of drawing the shape's outline. You can draw an outline using different line widths, line styles, and colors.
Painting and stroking are very closely related. Stroking, in fact, is just the process of creating a shape that represents an outline and filling it. You can draw outlines using any type of paint. Figure 4-1 shows some examples. On the left, a circle has been filled with a color gradient. In the middle, the same circle's outline is drawn with a thick line using a solid color. On the right, the circle's outline is drawn with the same thick line using the color gradient.
The following class produces the window shown in Figure 4-1. It uses some unfamiliar methods and classes: setPaint(), setStroke(), GradientPaint, and BasicStroke. I'll explain these classes and methods, and more, in the rest of the chapter. For now, this example should show you some of the potential of painting and stroking:
import java.awt.*;
import java.awt.geom.*;

public class PaintingAndStroking

extends ApplicationFrame {
public static void main(String[] args) {

PaintingAndStroking f = new PaintingAndStroking();

f.setTitle("PaintingAndStroking v1.0");

f.setSize(300, 150);

f.center();

f.setVisible(true);
}

public void paint(Graphics g) {

Graphics2D g2 = (Graphics2D)g;

double x = 15, y = 50, w = 70, h = 70;

Ellipse2D e = new Ellipse2D.Double(x, y, w, h);

GradientPaint gp = new GradientPaint(75, 75, Color.white,

95, 95, Color.gray, true);

// Fill with a gradient.

g2.setPaint(gp);

g2.fill(e);

// Stroke with a solid color.

e.setFrame(x + 100, y, w, h);

g2.setPaint(Color.black);

g2.setStroke(new BasicStroke(8));

g2.draw(e);

// Stroke with a gradient.

e.setFrame(x + 200, y, w, h);

g2.setPaint(gp);

g2.draw(e);
}
}

‹  Return to Product Overview