Advanced Java Screen Update Techniques SD - PowerPoint PPT Presentation

About This Presentation
Title:

Advanced Java Screen Update Techniques SD

Description:

... Flicker ... Can cause flicker, since no optimizations are applied. Use ... Double Buffering to minimize flicker. Use Coordinate Transformations to scroll ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 21
Provided by: tedfa
Category:

less

Transcript and Presenter's Notes

Title: Advanced Java Screen Update Techniques SD


1
Advanced Java Screen Update TechniquesSD98 -
Session 4406
  • Ted Faison
  • ted.faison_at_computer.org
  • Faison Computing Inc.
  • www.faisoncomputing.com

2
Painting with the 2D API
  • Everything is just a Shape
  • The Shape interface and its main methods
  • boolean contains(Point2D)
  • Rectangle getBounds()
  • PathIterator getPathIterator(AffineTransform)
  • boolean Intersects(Rectangle2D)
  • GeneralPath, Bezier Curves
  • Rectangles, Polygons, Ellipses, Arcs
  • Text

3
2D Drawing Examples
  • Drawing a geometric shape
  • DrawingRectangles.java
  • Filling a shape
  • FillingRectangles.java
  • Drawing the outline of a shape
  • TextOutline.java

4
Flicker and repaint ( )
  • What repaint() does
  • Erases component background
  • Sets graphics context color
  • Calls paint()
  • Flicker is produced by the background erasure
  • Example
  • RectWithFlicker.java

5
Minimizing Flicker
  • Tips
  • Call paint() directly, instead of repaint(), if
    the component has no transparent areas
  • Don't erase areas you're going to paint over

6
Moving components on the screen
  • SetLocation causes the AWT to erase the old image
    and draw the new one.
  • Can cause flicker, since no optimizations are
    applied
  • Use a silhouette
  • a lightweight outline XORed to the screen
  • Extremely fast
  • Example UsingSilhouettes.java

7
Double Buffering
  • An example
  • OffScreenImage.java
  • Using BufferedImage
  • gives control over transparency and blending
  • examples
  • OffScreenBufferedImage.java
  • OffScreenBufferedImageWithTransparency.java

8
Shaping the area painted Clipping Regions
  • Using Graphics.setClip
  • JDK 1.1 supported only rect
  • Graphics.setClip(int, int, int, int)
  • JDK 1.2 also supports arbitrary shapes
  • Graphics2D.setClip(Shape)

9
Improving Screen Update Speed with Clipping
  • Use rectangular clipping areas only
  • Examples
  • Rectangles RectMovingWithClipping.java
  • Images ImageMovingWithClipping .java
  • Shapes ShapeMovingWithClipping.java
  • uses coordinate transformations to move shape

10
Coordinate Transformations
  • Functions that map a point in one space to a
    point in another space
  • Represented using a 3x3 matrix
  • Transformations require multiplying each pixel by
    the transformation matrix
  • Positive angles rotate the X axis towards the Y
    axis
  • Can be used to invert axes, bend images, distort
    space arbitrarily

11
Coordinate Transformations
a11 a12 a13 a21 a22 a23 0 0 1
x y 1
a11x a12y a13 a21x a22y a23 0 0
1
x y 1


12
Affine Transforms
  • Maintain straightness and parallelism
  • Translation
  • setToTranslation(double dx, double, dy)
  • used to support graphics scrolling

Device Space
User Space
13
Affine Transforms
  • Rotation
  • Rotating about the origin
  • setToRotation(double theta)

Device Space
User Space
14
Affine Transforms
  • Rotation about an arbitrary point
  • SetToRotation(theta, x, y)

(x, y)
(x, y)
Device Space
User Space
15
Affine Transforms
  • Shearing
  • setToShear(double sh, double sy)

Device Space
User Space
16
Affine Transforms
  • Scaling
  • setToScale(double sx, double sy)
  • anisotropic vs isotropic scaling

Device Space
User Space
17
Affine Transforms
  • Handling transformed images with offscreen
    buffers
  • Examples
  • OffScreenTransformedImage.java
  • ScalingImages.java
  • RotatingImages.java
  • ShearingImages.java

18
Batch Painting
  • A technique to speed up rendering
  • Used internally by the Graphics2D context
  • Batch a block of contiguous pixels with the same
    Paint object

19
Drawing Patterns
  • Patterns require BufferedImage and TexturePaint
    objects
  • Example PatternedBackgrounds.java
  • Filling Shapes with Patterns
  • Example FillingShapeWithPattern.java
  • Example FillingTextWithPattern.java

20
Conclusion
  • Use Double Buffering to minimize flicker
  • Use Coordinate Transformations to scroll and zoom
  • Everything is a Shape, with support for stroking,
    gradient filling and pattern filling
  • Batch painting internally increases screen update
    speed
Write a Comment
User Comments (0)
About PowerShow.com