How does Java Graphics.drawImage() work and what is the role of ImageObserver

后端 未结 4 1084
傲寒
傲寒 2020-12-09 17:12

How should Java\'s drawImage() be used? I do not find the JDK documentation very forthcoming. For example all drawImage signatures require an ImageObserver but the documenta

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 17:39

    Image objects aren't necessarily completely loaded. If Graphics.drawImage is invoked on an incomplete image it will draw as much of the image as it can, and then alert the ImageObserver (by calling imageUpdate) when more of the image is loaded.

    The ImageObserver can be null, in which case you won't get any notification. This is common if the images are known to be loaded, or if there's already another mechanism doing repaints.

    Note that Component implements ImageObserver, and its imageUpdate method will cause a repaint on the affected area.

提交回复
热议问题