《Java编程技巧1001条》 第605条: 检测图像装入过程
2017-12-27 11:37
633 查看
《Java编程技巧1001条》第13部分 多媒体程序设计
第605条 检测图像装入过程
605 Overriding imageUpdate Method to Detect Progress of Imaging Loading
605 利用imageUpdate方法来检测图象安装是否成功
In the previous tip, you learned that Java calls the imageUpdate method as it loads a graphics image. By overriding the imageUpdate method, you can monitor the progress of the image-loading operation. The following applet, img_progress.java, displays progress messages to the status window to indicate that image loading is in progress:
在以上TIP中, 你已了解Java在安装图象时调用了imageUpdate方法. 通过imageUpdate的调用, 你可以监示图象安装操作的进行. 以下的小应用程序img_progress.java在状态行窗口中显示了过程信息,指示图象正在安装之中:
import java.applet.*;
import java.awt.*;
public class img_progress extends Applet implements Runnable {
int load_index = 0;
Thread progress = null;
Image bg_img;
String ld_str[] = {"loading * ", "loading * ",
"loading * ", "loading *"};
public void init()
{
bg_img = getImage (getCodeBase(), "bgimg.jpg");
}
public void start()
{
if (progress == null)
{
progress = new Thread(this);
progress.start();
}
}
public void paint(Graphics g)
{
g.drawImage (bg_img, 0, 0, this);
}
public void run()
{
while (progress != null)
{
load_index++;
if (load_index > 3)
load_index = 0;
showStatus (ld_str[load_index]);
try {
Thread.sleep (300);
}
catch (InterruptedException e) {};
}
}
public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
{
if (img == bg_img)
{
if ((flags & ALLBITS) != 0)
{
if ( progress != null)
{
showStatus ("loaded");
progress.stop();
}
}
}
return super.imageUpdate(img, flags, x, y, w, h);
}
}
*** kaj describe the processing
相关文章推荐
- 《Java编程技巧1001条》第608条: 在装入图像时设置时间限制
- 《Java编程技巧1001条》第600条: 重用update方法来减少图像闪烁
- 《Java编程技巧1001条》第606条: 获得图像的大小尺寸
- 《Java编程技巧1001条》第607条: 利用MediaTraker预装图像
- 《Java编程技巧1001条》第604条:了解图像的观察器
- 《Java编程技巧1001条》353条:求随机浮点数
- 《Java编程技巧1001条》357条:用高斯分布建立随机数
- 《JAVA编程技巧1001条》第334条:数学函数 求绝对值.
- 计算机视觉目标检测的框架与图像处理过程
- 《JAVA编程技巧1001条》第335条:数学函数 SQRT.
- 《Java编程技巧1001条》第375条: 使用DOS下的 TZ 环境变量,
- 《Java编程技巧1001条》第592条: 播放声音剪辑
- 《JAVA编程技巧1001条》第337条:数学函数 SIN。
- 《Java编程技巧1001条》 第345条:使用ceil方法
- canny 算子实现图像边缘检测(详细过程附源码)
- 《JAVA编程技巧1001条》第338条:数学函数 TAN
- 《Java编程技巧1001条》 第346条:浮点数向上向下舍入方法
- 《Java编程技巧1001条》354条:了解伪随机与真随机
- 《Java编程技巧1001条》第609条: 建立推进特殊效果
- 基于haar分类器特征提取及检测图像全过程(V0.1)