.newFixedThreadPool(threadCount + 1);
// 线程池的创建服务器
Runnable calculateBitmapWorker = new Runnable() {
@Override
public void run() {
Bitmap thumb = null;
try {
if (isThumbPath) {
thumb = BitmapFactory.decodeFile(thumbPath);
if (null == thumb) {
thumb = revitionImageSize(sourcePath);
}
} else {
thumb = revitionImageSize(sourcePath);
}
} catch (Exception e) {
}
if (null == thumb) {
thumb = PickPhotoActivity.bimap;
}
put(path, thumb);
final Bitmap bmpToCallback = thumb;
if (null != callback) {
handler.post(new Runnable() {
@Override
public void run() {
callback.imageLoad(iv, bmpToCallback, sourcePath);
}
});
}
}
};
executorService.execute(calculateBitmapWorker);
本文介绍了一个使用Java线程池加载并处理图片的例子。该示例通过创建固定大小的线程池来异步加载图片,并根据路径解码图片为Bitmap对象。如果指定的缩略图路径无效,则尝试从源路径加载图片。加载完成后,图片会通过回调函数展示到ImageView中。
1090

被折叠的 条评论
为什么被折叠?



