毕加索加载所有手机照片的缩略图

Dab*_*ler 6 android photos picasso

我希望从手机中显示所有照片,并使用Picasso在gridview中显示它们.问题是我不知道如何实现这一点.

目前我正在使用此查询所有手机照片:

Cursor cursor;
    String[] columns = new String[] {
            MediaStore.Images.ImageColumns._ID,
            MediaStore.Images.ImageColumns.TITLE,
            MediaStore.Images.ImageColumns.DATA};
    cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            columns, null, null, null);
    int columnIndex = cursor.getColumnIndex(MediaStore.Images.Thumbnails._ID);
    int columnPath = cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA);
Run Code Online (Sandbox Code Playgroud)

和MediaStore.Images.Thumbnails.getThumbnail一样,将缩略图的位图注入ImageView.

我怎么能用毕加索来实现呢?

Seb*_*ano 4

很简单。只需使用Uri.withAppendedPath构建 URI,然后将其提供给 Picasso。后者将在内部使用它MediaStoreRequestHandler来获取正确的图像。

// Use the cursor you've defined (correctly)
int columnIndex = cursor.getColumnIndex(MediaStore.Images.Thumbnails._ID);
Uri imageURI = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(columnIndex));
Picasso
  .with(context)
  .load(imageURI)
  .fit()
  .centerInside()
  .into(imageView);
Run Code Online (Sandbox Code Playgroud)

  • 这不会获得正确的缩略图,因为您提供“columnIndex”作为要显示的图像的 ID。使用默认投影,列索引为 0,因此您只需获取媒体存储中的第一个缩略图。 (2认同)