0
votes

i'm building a file explorer application, and i'm trying to load large amount of images (more then 5000...), i'm trying to use picasso but its still slow so i'm trying to load a Thumbimage with picasso and not the whole image file..

    ....
    ImageItem item = data.get(position);
    ImageView imageView = holder.image;
    Bitmap ThumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(item.getImage().getPath()), 100, 100);
    Picasso.with (context) .load (ThumbImage ) .into (imageView); /*/ doesnt work.. cant load ThumbImage with Picasso
    Picasso.with (context) .load (item.getImage()) .into (imageView); //work, but too slow

i cant figure out how can i load Thumbimage into ImageView with Picasso.. there is any why to do that? another way to load faster my images?

1
are the images yours? - Tasos
yes, from camera (DCIM folder) - Nirel
then you will still have performance issues. best to create another App that gets all the images from the camera folder and creates thumb's for them so you will have 2 images. the small one and the big one. Then in the app you are working with now loads in the small ones from the camera folder . or consolidate the 2 into one app but i suggest creating thumb's for all images permanently in the camera folder - Tasos
@Nirel What View are you loading these images into? A RecyclerView? And why can't you load the Bitmap? Does it give you an error, or does it just not show up? - Bryan
Gridview custom adapter (textview+imageview for each row), error, can't load bitmap with Picasso - Nirel

1 Answers

2
votes

First I would recommend using RecyclerView instead of a GridView, considering it handles a lot of the memory management for you. Instead of having to load all of the images at once (or manage it yourself), it will only load the images that fit on the screen. And you can use a GridLayoutManager to have it appear just as it would in a GridView.

RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler);
recyclerView.setLayoutManager(new GridLayoutManager(context, 4);
recyclerView.setAdapter(new MyRecyclerViewAdapter(context, data);

Also, let Picasso handle converting the image for you, this way you do not need to use ThumbnailUtils. Picasso handles image resizing and memory management with the resize() function:

String uri = data.get(position);

Picasso.with(context).load(new File(uri)).resize(100, 100)
  .centerCrop().into(imageView)

You can do this in the onBindViewHolder() method of the RecyclerView.Adapter so that each image will only be loaded when the View has to be shown.

I am not sure how you are obtaining the images currently, but if you do not know how to obtain the URI of the image, this should work:

String[] projection = {"*"};

List<String> data = new ArrayList<>();

Cursor cursor = context.getContentResolver().query(
        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);

if(cursor.moveToFirst()) {
    do {
        data.add(cursor.getString(cursor
                        .getColumnIndex(MediaStore.Images.Media.DATA)));
    } while(cursor.moveToNext());
}

I do not know if this will fix the problem you have with Picasso not loading the images, but if it does not post a stack trace and we can try to figure that out.