Java 2D Graphics Dimension d = getSize(); int
Java 2D Graphics 14.2.5 Animated Images I’ve discussed how shapes and text perform under different circumstances. Now let’s take a look at the third graphic type images. There aren’t quite as many variables to fiddle with, mostly because the image contains its own color data. The current Paint of the Graphics2D doesn’t affect how images are drawn. Even antialiasing isn’t a factor. Several aspects of images are important for performance. The following example animates an image, in the same spirit as Bouncer and TextBouncer. The running application is shown in Figure 15.32. A small image bounces around the window. You can choose to transform the image as it is rendered, and you can choose from a short list of image storage types. The transformation is a simple rotation, performed at the center of the image. You can, however, choose the interpolation algorithm that is used when the image is rotated. This algorithm specifies how the colors of the rotated image are determined. The default is the “nearest neighbor” algorithm, which is fast but sloppy. As the example runs, you can see the “jaggies” that result from this algorithm in the borders between the hair on my head and the background of the image. If you instead use “bilinear interpolation” (by checking the Bilinear checkbox), the rotated picture will be higher quality, but the animation will be slower. The combo box lets you choose what basic image type will be rendered. Some image types require color conversions before the image can be rendered on your screen. For example, if the base type is TYPE_BYTE_GRAY and you have a color display, the grayscale pixels of the image will have to be converted to red, green, and blue values before the image can be displayed on the screen. Here’s the code for the ImageBouncer example: import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.awt.image.*; import java.util.Random; public class ImageBouncer extends AnimationComponent { public static void main(String[] args) { String filename = “knudsen.gif”; if (args.length > 0) filename = args[0]; Image image = Utilities.blockingLoad(filename); final ImageBouncer bouncer = new ImageBouncer(image); Frame f = new AnimationFrame(bouncer); f.setFont(new Font(”Serif”, Font.PLAIN, 12)); Panel controls = new Panel(); controls.add(bouncer.createCheckbox(”Bilinear”, ImageBouncer.BILINEAR)); controls.add(bouncer.createCheckbox(”Transform”,ImageBouncer.TRANSFORM)); final Choice typeChoice = new Choice(); typeChoice.add(”TYPE_INT_RGB”); typeChoice.add(”TYPE_INT_ARGB”); typeChoice.add(”TYPE_INT_ARGB_PRE”); typeChoice.add(”TYPE_3BYTE_BGR”); typeChoice.add(”TYPE_BYTE_GRAY”); typeChoice.add(”TYPE_USHORT_GRAY”); typeChoice.add(”TYPE_USHORT_555_RGB”); typeChoice.add(”TYPE_USHORT_565_RGB”); controls.add(typeChoice); f.add(controls, BorderLayout.NORTH); page 267
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services