Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison Faison Computing Inc.

Similar presentations


Presentation on theme: "Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison Faison Computing Inc."— Presentation transcript:

1 Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison ted.faison@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 a 11 a 12 a 13 a 21 a 22 a 23 0 0 1 xy1xy1 a 11 x a 12 y a 13 a 21 x a 22 y a 23 0 0 1 x’ y’ 1 ==

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

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

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

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

16 Affine Transforms Scaling setToScale(double sx, double sy) anisotropic vs isotropic scaling User Space Device 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


Download ppt "Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison Faison Computing Inc."

Similar presentations


Ads by Google