Util:ImageLoad图片缩放处理
来源:互联网 发布:激光聚焦矩阵 mc百科 编辑:程序博客网 时间:2024/06/01 19:31
public class ImageLoadTask extends AsyncTask<Void, Void, Void> {
private MyListViewAdapter adapter;
private List<ArchRequest> archRequestList;
private LoadingDialog loadingDialog;
private Context context;
public ImageLoadTask(Context context,MyListViewAdapter adapter, List<ArchRequest> archRequestList,LoadingDialog loadingDialog) {
this.context = context;
this.adapter = adapter;
this.archRequestList = archRequestList;
this.loadingDialog = loadingDialog;
}
@Override
protected Void doInBackground(Void... params) {
for (int i = 0; i < adapter.getCount(); i++) {
ImageBean bean = (ImageBean) adapter.getItem(i);
if(archRequestList.get(i) != null){
ArchResponse archResponse= SyncApi.getArch(archRequestList.get(i));
if(archResponse != null){
byte[] b = archResponse.getArchData();
if (b!= null && b.length != 0) {
bean.setBitmap(createBitmap(b,80,80));
}
}
}
bean.setNeedBar(false);
publishProgress(); // 通知去更新UI
}
return null;
}
public void onProgressUpdate(Void... voids) {
if (isCancelled()) {
return;
}
// 更新UI
loadingDialog.dismiss();
adapter.notifyDataSetChanged();
}
/**
* @param data 数据或路径
* @param width 目标宽
* @param height 目标高
* @return 图片
*/
private Bitmap createBitmap(Object data, int width, int height) {
Options options = new Options();
int scale = 1;
if (width > 0 && height > 0) {//创建目标大小的图片
options.inJustDecodeBounds = true;
if (data instanceof String) {
BitmapFactory.decodeFile((String) data, options);
} else {
BitmapFactory.decodeByteArray((byte[]) data, 0, ((byte[]) data).length, options);
}
int dw = options.outWidth / width;
int dh = options.outHeight / height;
scale = Math.max(dw, dh);
options = new Options();
}
options.inDensity = DeviceInfo.getInstance().getDencity();
options.inScaled = true;
options.inPurgeable = true;
options.inSampleSize = scale;
Bitmap bitmap = null;
if (data instanceof String) {
bitmap = BitmapFactory.decodeFile((String) data, options);
} else {
bitmap = BitmapFactory.decodeByteArray((byte[]) data, 0, ((byte[]) data).length,
options);
}
return bitmap;
}
}
private MyListViewAdapter adapter;
private List<ArchRequest> archRequestList;
private LoadingDialog loadingDialog;
private Context context;
public ImageLoadTask(Context context,MyListViewAdapter adapter, List<ArchRequest> archRequestList,LoadingDialog loadingDialog) {
this.context = context;
this.adapter = adapter;
this.archRequestList = archRequestList;
this.loadingDialog = loadingDialog;
}
@Override
protected Void doInBackground(Void... params) {
for (int i = 0; i < adapter.getCount(); i++) {
ImageBean bean = (ImageBean) adapter.getItem(i);
if(archRequestList.get(i) != null){
ArchResponse archResponse= SyncApi.getArch(archRequestList.get(i));
if(archResponse != null){
byte[] b = archResponse.getArchData();
if (b!= null && b.length != 0) {
bean.setBitmap(createBitmap(b,80,80));
}
}
}
bean.setNeedBar(false);
publishProgress(); // 通知去更新UI
}
return null;
}
public void onProgressUpdate(Void... voids) {
if (isCancelled()) {
return;
}
// 更新UI
loadingDialog.dismiss();
adapter.notifyDataSetChanged();
}
/**
* @param data 数据或路径
* @param width 目标宽
* @param height 目标高
* @return 图片
*/
private Bitmap createBitmap(Object data, int width, int height) {
Options options = new Options();
int scale = 1;
if (width > 0 && height > 0) {//创建目标大小的图片
options.inJustDecodeBounds = true;
if (data instanceof String) {
BitmapFactory.decodeFile((String) data, options);
} else {
BitmapFactory.decodeByteArray((byte[]) data, 0, ((byte[]) data).length, options);
}
int dw = options.outWidth / width;
int dh = options.outHeight / height;
scale = Math.max(dw, dh);
options = new Options();
}
options.inDensity = DeviceInfo.getInstance().getDencity();
options.inScaled = true;
options.inPurgeable = true;
options.inSampleSize = scale;
Bitmap bitmap = null;
if (data instanceof String) {
bitmap = BitmapFactory.decodeFile((String) data, options);
} else {
bitmap = BitmapFactory.decodeByteArray((byte[]) data, 0, ((byte[]) data).length,
options);
}
return bitmap;
}
}
0 0
- Util:ImageLoad图片缩放处理
- imageload控件处理加载图片闪动的问题
- ImageLoad图片加载器
- 使用imageload加载图片
- imageload缓存图片
- java 图片缩放处理
- ios 处理图片缩放
- iOS 图片缩放处理
- Bitmap图片缩放处理
- imageload(listview图片加载错位)
- 上传图片的缩放处理
- 上传图片的缩放处理
- 上传图片的缩放处理
- java图片缩放剪切处理
- objective-c处理图片缩放
- Android图片的缩放处理
- 提取图片的缩放处理
- java图片处理:缩放、剪切
- 华为OJ(MP3光标移动)
- 经典任务调度算法的模拟程序
- 数组和指针内存分配示例代码
- Makefile经典教程(掌握这些足够)
- 架构师不是演员,是管家
- Util:ImageLoad图片缩放处理
- ios学习计划
- 浅谈java中的ServerSocket和Socket的通信原理实现聊天及多人聊天
- java collection容器
- POJ 2777 Count Color (线段树区间修改 + 状态压缩)
- BufferedReader子类LineNumberReader装饰类的简单介绍
- js的screen对象
- 设计模式之装饰模式
- c++程序设计课程--简单的设计任务