2017-08-12 62 views
0

所以我正在制作一个显示捕获图像的应用程序。我首先将捕获的图像保存在String的静态ArrayList中(在下面的代码中:methods.locationPath),然后将这些字符串转换为位图并将它们保存在位图的ArrayList中(在下面的代码中:图像)。加载位图需要的时间太长

for (String path : methods.locationPath) { 
    Bitmap bitmap = BitmapFactory.decodeFile(path); 
    images.add(bitmap); 
} 

gr = (GridView) findViewById(R.id.grid); 
GridAdapter gridAdapter = new GridAdapter(this, values,images); 
gr.setAdapter(gridAdapter); 

然而,这种方法花费的时间太长。有没有办法通过尽可能小的更改来使此循环更快?

谢谢

+0

使用图像加载库,如毕加索或滑翔图像,根据需要异步加载的图像。 – CommonsWare

回答

1

而不是将图像路径更改为Bitmap对象。可以直接通过图像的路径和上适配器类设置像

Picasso.with(mContext).load(new File(imageUrl)).resize(100,100).into(myViewHolder.imageView, new Callback() { 
       @Override 
       public void onSuccess() { 
         } 

       @Override 
       public void onError() { 

       } 
      });