使用GirdView异步加载图片,并对图片进行颜色矩阵变化
来源:互联网 发布:北方航空公司招聘java 编辑:程序博客网 时间:2024/05/16 05:10
http://www.eoeandroid.com/thread-148172-1-1.html
实现异步加载
原理:GridViewAdapt 里面设置List<Bitmap>,线程更新此List并通知Adapt实现动态加载功能
核心代码 :
adapt:
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
GridView.LayoutParams params = new GridView.LayoutParams(90, 90);
imageView.setLayoutParams(params);
imageView.setImageBitmap(bitmapList.get(position));
return imageView;
}
AsyncTask:
public class GridViewAsyncTask extends AsyncTask<String, ImageBean, Bitmap>
//此方法用来取到所有的图片路径
protected Bitmap doInBackground(String... params) {
for(int position=0; position<params.length;position++)
{
Bitmap bitmap = null;
//更新图片
bitmap = MapHandleUtil.bitmap_Out_Of_Memory_Handle(params[position],90,90);
if (bitmap != null) {
//通知线程进行UI更新
publishProgress(new ImageBean(bitmap,position));
}
}
return null;
}
//对UI线程更新
public void onProgressUpdate(ImageBean... value) {
for (ImageBean image : value)
{ //修改Adapt中List<Bitmap>
gridViewAdapt.getBitmapList().add(image.getBitmap());
//通知adapt进行更新
gridViewAdapt.notifyDataSetChanged();
}
}
对Bitmap过大产生的oo异常进行优化
//处理图片内存溢出处理//并添加缩略图
//本方法并不是最好的方法,在图片过大时还是会溢出,欢迎大家拍砖修改
public static Bitmap bitmap_Out_Of_Memory_Handle(String bitmapPath,int w,int h)
{
//取得图片Bitmap数组
InputStream inputStream;
byte[] len = null ;
try {
inputStream = new FileInputStream(bitmapPath);
len = DataUtil.streamToBytes(inputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//为取得图片宽高又不至于过多的占用内存采用修改options的方法
// 这样取得的图片占用内存较小
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap bm = BitmapFactory.decodeByteArray(len, 0, len.length);
options.inJustDecodeBounds = false;
if(bm ==null)
{
return null;
}
int src_w = bm.getWidth();
int src_h = bm.getHeight();
float scale_w = ((float)w)/src_w;
float scale_h = ((float)h)/src_h;
Matrix matrix = new Matrix();//设置图片宽高矩阵
matrix.postScale(scale_w, scale_h);
Bitmap bitmap = Bitmap.createBitmap(bm, 0, 0, src_w, src_h, matrix, true);
bm.recycle();
return bitmap;
}
- 使用GirdView异步加载图片,并对图片进行颜色矩阵变化
- 使用异步加载图片
- 异步批量加载网络图片,并使用二级缓存.
- 使用Palette来对图片进行颜色提取
- android异步加载图片显示,并且对图片进行缓存实例
- android异步加载图片显示,并且对图片进行缓存实例
- Android使用 argb, 矩阵,像素点对图片进行修改
- Android批量图片加载经典系列——使用LruCache、AsyncTask缓存并异步加载图片
- android 使用异步加载图片
- 使用AsyncTask异步加载图片
- 使用Ajax异步加载图片
- android加载网络图片并缓存,对图片进行点击打开相应链接
- listview异步加载图片并防止错位
- 对图片上的颜色进行转换
- 使用ImageLoader进行图片加载
- ImageView加载图片资源并进行缩放
- 我的Android进阶之旅------>android异步加载图片显示,并且对图片进行缓存实例
- Android有效加载图片 之 使用AsyncTask异步加载图片
- MyEclipse 8.5注册码
- SVN FAQ. UPDATING...
- C#中StringBuilder类的使用
- HTML5并非万能,至少目前有5件事做不成
- 宏基笔记本4749 硬盘模式从 ide 切换到ahci
- 使用GirdView异步加载图片,并对图片进行颜色矩阵变化
- Sphnix中文全文搜索引擎-安装篇
- c#中各种符号的用法释义
- 自己整理的一个读书学习的计划,打算全部买纸质书来学习
- Error while performing database login with the XXX driver:Io 异常: The Network Adapter could not estab
- ListView getView()多次调用 -----ActivityGroup所致,已解决~~
- StrutsPrepareAndExecuteFilter源码剖析
- FI顾问基础知识
- 拔苗助长:中国的孩子全部输在起跑线上