《Java编程技巧1001条》第604条:了解图像的观察器
2017-12-27 11:31
736 查看
《Java编程技巧1001条》第13部分 多媒体程序设计
第604条 了解图像的观察器
604 Understanding the ImageObserver
604 了解ImageObserver(图象观察器)
kaj better define the imageobserver
When your program calls the drawImage method to display an image, Java first checks to see if the image is available (if the image has been loaded and is ready for display). If the image is unavailable, the drawImage method returns without drawing the image, but will notify the ImageObserver of its progress. Java sends the notification message to the ImageObserver by calling the observers imageUpdate method, as shown in the following statement:当你的程序调用drawImage 方法在屏幕上显示一图象时, Java首先要检查图象是否可用(图象是否已安装,是否已准备好显示). 如果图象还不能使用, 则调用drawImage 方法时将不画图象就返回, 但会通知ImageObserver它已结束.Java通过调用imageUpdate方法把这个通知消息送给ImageObserver,如下所示:
boolean imageUpdate(Image img, int infoflags, int x, int y,
int width, int height);
The img parameter specifies for which image Java is sending the
notification. The infoflags argument specifies the type of information the
message contains. The infoflags argument is a bit-mask variable whose bits
can represent a combination of the values listed in Table 604.
其中参数img指定了java为哪一个图象发送通知. 变元infoflags 定义了消息包含的信
息类型. 变元infoflags是一个用二进制位表示的变量, 它的各个位可表示如表604所
示的各种值的组合:
Bit Field Meaning
------------------------------------------------------------------------
ABORT Image production was aborted
ALLBITS Image is completed
ERROR An error was encountered
FRAMEBITS A new image frame is completed
HEIGHT Height information is now available
PROPERTIES Image property information is now available
SOMEBITS Part of the image is available
WIDTH Width information is now available
------------------------------------------------------------------------
Table 604 Flag values specified by an imageUpdate message.
位 意义
------------------------------------------------------------------------
ABORT 图象输出已被放弃
ALLBITS 图象已完成
ERROR 遇到一个错误
FRAMEBITS 一幅新图象已结束
HEIGHT 高度信息已可用
PROPERTIES 图象属性信息已可用
SOMEBITS 部分图象已可用
WIDTH 宽度信息已可用
------------------------------------------------------------------------
表 604 由一个 imageUpdate 消息所规定的标志值
By default, the imageUpdate method calls the repaint method to redraw the screen area, even in the case when the image is only partially available. As you will learn in Tip 605, by overriding the imageUpdate method, your programs can detect when the image is loaded and ready for display.
按缺省, imageUpdate调用repaint方法来重画屏幕区, 即使图象只有部分可用也是这样. 在TIP 605中你将会知道。
相关文章推荐
- 《Java编程技巧1001条》第606条: 获得图像的大小尺寸
- 《Java编程技巧1001条》第607条: 利用MediaTraker预装图像
- 《Java编程技巧1001条》第608条: 在装入图像时设置时间限制
- 《Java编程技巧1001条》354条:了解伪随机与真随机
- 《Java编程技巧1001条》 第605条: 检测图像装入过程
- 《Java编程技巧1001条》第373条: 了解不同的日期标准,
- 《Java编程技巧1001条》第600条: 重用update方法来减少图像闪烁
- 《Java 编程技巧1001条》 第389条: 了解不平衡数组
- 《Java 编程技巧1001条》第402-406条: 了解事件驱动程序,
- 《Java 编程技巧1001条》第414条:了解键盘事件
- 《Java编程技巧1001条》第362条: 用日期类 建立你自己的 日期/时间
- 《Java 编程技巧1001条》 第403条: 了解事件类
- 《Java 编程技巧1001条》 第404条: 了解实用方法
- 《Java编程技巧1001条》第603条: 使用双缓冲器改进动画
- 《JAVA编程技巧1001条》第334条:数学函数 求绝对值.
- 《Java编程技巧1001条》第592条: 播放声音剪辑
- 《Java 编程技巧1001条》 第382+283条: 了解数组的长度和引用
- 《Java 编程技巧1001条》 第392条: 了解2分查找
- 《Java 编程技巧1001条》第412条...: 了解多按钮鼠标问题
- 《JAVA编程技巧1001条》第335条:数学函数 SQRT.