非同期の読み込みパフォーマンスを向上させるには、独自の imageUpdate() メソッドを使用して imageUpdate() をオーバーライドします。imageUpdate() は、必要以上に再描画を行うことがあります。
//wait for the width information to be loaded
while (image.getWidth(null) == -1 {
try {
Thread.sleep(200);
}
catch(InterruptedException e) {
}
}
if (!haveWidth) {
synchronized (im) {
if (im.getWidth(this) == -1) {
try {
im.wait();
}
catch (InterruptedException) {
}
}
}
//If we got this far, the width is loaded, we will never go thru
// all that checking again.
haveWidth = true;
}
...
public boolean imageUpdate(Image img, int flags, int x, int y, int width, int height) {
boolean moreUpdatesNeeded = true;
if ((flags&ImageObserver.WIDTH)!= 0 {
synchronized (img) {
img.notifyAll();
moreUpdatesNeeded = false;
}
}
return
moreUpdatesNeeded;
}
|