BufferedImage getBufferedImage(){
//Larger images produce better quality.
double imageSize = 10.0;
BufferedImage theBufferedImage =
(BufferedImage)this.createImage(
(int)(imageSize*ds),
(int)(imageSize*ds));
//Get a Graphics2D context on
// the BufferedImage object
Graphics2D g2dImage =
theBufferedImage.createGraphics();
//Draw a rectangle on the
// Graphics2d context on the
// BufferedImage and fill it with
// the color green.
Rectangle2D.Double theRectangle =
new Rectangle2D.Double(
0.0,0.0,imageSize*ds,
imageSize*ds);
g2dImage.setPaint(new Color(0,255,0));
g2dImage.fill(theRectangle);
g2dImage.draw(theRectangle);
//Draw a circle on the Graphics2d
// context on the BufferedImage and
// fill it with the color red.
// This circle will cover the green rectangle.
Ellipse2D.Double circleOntheBufferedImage
= new Ellipse2D.Double(
0.0,0.0,imageSize*ds,
imageSize*ds);
//red
g2dImage.setPaint(new Color(255,0,0));
g2dImage.fill(circleOntheBufferedImage);
g2dImage.draw(circleOntheBufferedImage);
return theBufferedImage;
}//end getBuffered Image
}//end class GUI
//==============================//
Figure 12
|