Java Graphics.drawImage()如何工作以及ImageObserver的作用是什么 [英] How does Java Graphics.drawImage() work and what is the role of ImageObserver

查看:444
本文介绍了Java Graphics.drawImage()如何工作以及ImageObserver的作用是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Java的drawImage()?我没有找到JDK文档。例如,所有drawImage签名都需要一个ImageObserver,但是这个文档对新用户来说并不是很有用。

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 documentation for this is not very helpful for new users.

推荐答案

你可以逃脱使用 Graphics.drawImage(img,x,y,null) [或类似]。 ImageObserver 参数是一个回调函,用于通知您绘制操作的进度;并且只有在异步获取Image参数时才真正有用。

You can get away with Graphics.drawImage(img, x, y, null) [or similar]. The ImageObserver parameter is a callback to inform you of the progress of the draw operation; and is really only useful if you're fetching the Image parameter asynchronously.

更清楚一点,如果你调用 drawImage 对于未完全加载的图像,它将:

To be clearer, if you call drawImage with an incompletely loaded Image it will:


  1. 返回false(立即)

  2. 绘制尽可能多的尽可能图像(所有已加载的)

  3. 并且,在将来的某个时刻,调用 ImageObserver 当有更多图像可用时

  1. return false (immediately)
  2. draw as much of the Image as possible (all that is loaded)
  3. and, at some future point, call into the ImageObserver when more of the Image is available

基本上,如果你在内存中工作 Image s(从文件系统加载,或由程序构建)不要担心 ImageObserver 参数。如果您在网络上加载 Image 并且未明确等待加载,则需要使用 ImageObserver 确保完全绘制图像

Basically, if you're working with in memory Images (either loaded from the file system, or constructed by your program) don't worry about the ImageObserver parameter. If you're loading Images across the network and not explicitly waiting for them to load, you'll need to employ an ImageObserver to make sure "completely" draw an Image.

这篇关于Java Graphics.drawImage()如何工作以及ImageObserver的作用是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆