Ch2-1 by huangyuarong

VIEWS: 23 PAGES: 44

									Basic Principles of 2D Graphics
Raster Graphics
 aka pixel or pixel-oriented graphics.
 Colors are assigned to each pixel.
 Used for computer monitors, printers, and file formats
  like bitmap or jpg
 All geometrical shapes must be converted to pixels
   Leads to high computational efforts
   Possible aliasing effects (aka jaggies)
   Bound to specific resolution
Vector Graphics
 Efficient storage
 Scalable
SimpleJava2DExample
 Code necessary:
    SimpleJave2DExample
    MyFinishWindow
Window Coordinates
 To find the exact width of the margins (usually this is
  not necessary, but the ability is available)

      Insets ins = this.getInsets();

This statement places the width of the left, right, upper,
  and lower margin in pixels and can be retrieved by:
ins.left, ins.right, ins.top, and ins.bottom.
Drawing
 In Java2D, you first define your objects. However, none
 of them will appear on the screen until they are either
 drawn or filled.
2D Rendering Process
 Simple 2D Graphics programs can be outlined as
 follows:
   Construct 2D Objects
   Apply transformations on those objects
   Apply color and other rendering properties
   Render the scene on a graphics device
2D Geometry
 2D Geometric objects are made up of an infinite
  number of points in a plane.
 They can be represented efficiently through geometric
  equations or parametric equations that describe the
  objects
Shapes
 Object implement the “Shape” interface with a draw
  and fill method.
 Useful facts and examples:
  http://www.apl.jhu.edu/~hall/java/Java2D-
  Tutorial.html#Java2D-Tutorial-Shapes
CurveDemo.java
 For an example of how to create curves in Java2D, click
 here.
GeneralPath
 Car Example Code

								
To top