Java Multimedia Images Animation Audio and Video Outline

  • Slides: 8
Download presentation
Java Multimedia: Images, Animation, Audio and Video Outline 30. 1 30. 2 30. 3

Java Multimedia: Images, Animation, Audio and Video Outline 30. 1 30. 2 30. 3 30. 4 30. 5 30. 6 30. 7 30. 8 30. 9 Introduction Loading, Displaying and Scaling Images Loading and Playing Audio Clips Animating a Series of Images Animation Issues Customizing Applets via the HTML param Tag Image Maps Java Plug-In Internet and World Wide Web Resources 2000 Prentice Hall, Inc. All rights reserved.

30. 1 Introduction • Revolution in computer industry – Before, computers used for high-speed

30. 1 Introduction • Revolution in computer industry – Before, computers used for high-speed calculations – Now, data manipulation important • Multimedia – "sizzle" of Java - images, sound, video – CDs, DVDs, video cards – Demands extraordinary computing power • Fast processors making multimedia possible • Java – Has built-in multimedia capabilities • Most programming languages do not – Develop powerful multimedia applications 2000 Prentice Hall, Inc. All rights reserved.

30. 2 Loading, Displaying and Scaling Images • Java Multimedia – Graphics, images, animations,

30. 2 Loading, Displaying and Scaling Images • Java Multimedia – Graphics, images, animations, sounds, and video • Begin with images • Class Image (java. awt) – Abstract class, cannot create an object directly • Must request that an Image be loaded and returned to you – Class Applet (superclass of JApplet) has this method • get. Image( image. Location, filename ); • image. Location - get. Document. Base() - URL (address) of HTML file • filename - Java supports. gif and. jpg (. jpeg) 2000 Prentice Hall, Inc. All rights reserved.

30. 2 Loading, Displaying and Scaling Images (II) • Displaying Images with draw. Image

30. 2 Loading, Displaying and Scaling Images (II) • Displaying Images with draw. Image – Many overloaded versions g. draw. Image( my. Image, x, y, Image. Observer ); • my. Image - Image object • x, y - coordinates to display image • Image. Observer - object on which image is displayed – Use "this" to indicate the applet – Can be any object that implements Image. Observer interface – g. draw. Image( my. Image, x, y, width, height, Image. Observer ); • width and height - dimensions of image (automatically scaled) – get. Width(), get. Height() - return dimensions of applet 2000 Prentice Hall, Inc. All rights reserved.

30. 2 Loading, Displaying and Scaling Images (III) • Class Image. Icon – Not

30. 2 Loading, Displaying and Scaling Images (III) • Class Image. Icon – Not an abstract class (can create objects) – Example constructor private Image. Icon my. Icon; my. Icon = new Image. Icon( "my. Icon. gif" ); • Displaying Icons with method paint. Icon my. Icon. paint. Icon( Component, Graphics, x, y ) – Component - Component object on which to display image (this) – Graphics - Graphics object used to render image (g) – x, y - coordinates of Icon 2000 Prentice Hall, Inc. All rights reserved.

30. 2 Loading, Displaying and Scaling Images (IV) • Usage – Image. Icons are

30. 2 Loading, Displaying and Scaling Images (IV) • Usage – Image. Icons are simpler than Images • Create objects directly • No need for Image. Observer reference – However, cannot scale Image. Icons • Scaling – Use Image. Icon method get. Image • Returns Image reference • This can be used with draw. Image and be scaled 2000 Prentice Hall, Inc. All rights reserved.

1 2 3 4 5 6 7 8 9 10 11 12 13 14

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 // Fig. 30. 1: Load. Image. And. Scale. java Outline // Load an image and display it in its original size // and scale it to twice its original width and height. // Load and display the same image as an Image. Icon. import java. applet. Applet; import java. awt. *; import javax. swing. *; Image Example public class Load. Image. And. Scale extends JApplet { private Image logo 1; private Image. Icon logo 2; 1. 1 Declare objects // load the image when the applet is loaded public void init() { logo 1 = get. Image( get. Document. Base(), "logo. gif" ); logo 2 = new Image. Icon( "logo. gif" ); } // display the image public void paint( Graphics g ) { // draw the original image g. draw. Image( logo 1, 0, 0, this ); // draw the image scaled to fit the width of the applet // and the height of the applet minus 120 pixels g. draw. Image( logo 1, 0, 120, get. Width(), get. Height() - 120, this ); 2000 Prentice Hall, the Inc. icon All rights reserved. // draw using its paint. Icon method 1. import 2. init() 2. 1 Initialize objects 3. paint() 3. 1 draw. Image calls

32 logo 2. paint. Icon( this, g, 180, 0 ); 33 } Outline 34

32 logo 2. paint. Icon( this, g, 180, 0 ); 33 } Outline 34 } 3. 2 paint. Icon call Program Output 2000 Prentice Hall, Inc. All rights reserved.