您的位置:首页 > 编程语言 > Java开发

《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中你将会知道。 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: