资源预览内容
第1页 / 共10页
第2页 / 共10页
第3页 / 共10页
第4页 / 共10页
第5页 / 共10页
第6页 / 共10页
第7页 / 共10页
第8页 / 共10页
第9页 / 共10页
第10页 / 共10页
亲,该文档总共10页全部预览完了,如果喜欢就下载吧!
资源描述
第十章 Java的多媒体应用 n 图像显示n 动画实现n 声音处理10.1 图像显示nJava支持以下几种图像文件格式,nGIF (Graphics Interchange Format)nJPEG (Joint Photographic Experts Group)nPNG (Portable Network Graphics)。10.1 图像显示n显示图像文件步骤:1声明Image类的引用Image类在Java.awt包中。2应用getImage方法加载图像getImage方法是由Applet类定义的方法,两种格式:nImage getImage ( URL loc )nImage getImage ( URL loc, String name )10.1 图像显示3. 显示所加载的图像 Graphics类提供了drawImage()方法: public boolean drawImage(Image img, int left, int top ,ImageObserver imgObj) public boolean drawImage(Image img, int left, int top , Color bgc, ImageObserver imgObj) public boolean drawImage(Image img, int left, int top , int width, int height, ImageObserver imgObj) public boolean drawImage(Image img, int left, int top , int width, int height, Color bgc, ImageObserver imgObj)10.1 图像显示例10.1.1 在applet中显示meth. jpeg图像。 例10.1.2 用Swing组件显示meth. jpeg图象。 10.2 动画设计 动画(Animation)是利用了人眼的视觉特点, 把多幅图像进行连续显示的结果。 完成图像序列显示有多种方法。例10.2.1 用线程实现动画显示。例10.2.2 用时钟对象实现动画。 10.3 声音播放 nJava支持几种音频文件格式:au (Sun Audio file format)wav (Windows Wave file format)aif 或 aiff (Macintosh AIFF file format)MIDI 或 rmi (Music Instrument Digital Interface file format) 10.3 声音播放 n声音文件的播放步骤:1声明AudioClip类的引用声明音频对象。如:AudioClip audio 。2用getAudioClip()方法加载声音文件getAudioClip()方法是由Applet类定义 的实例方法,它有两种格式:nAudioClip getAudioClip ( URL loc )nAudioClip getAudioClip ( URL loc, String name )10.3 声音播放 3 控制声音文件的播放 通过AudioClip类的三个方法控制声音文件 的播放:nplay();播放声音文件一次nloop();循环播放声音文件nstop();结束当前正在播放的声音文件10.3 声音播放 例10.3.1 通过线程播放音频文件。例10.3.2 用swing组件播放多个音频文件。
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号