【问题标题】:Picasso loading thumbnails of all phone photos毕加索加载所有手机照片的缩略图
【发布时间】:2015-02-10 13:27:16
【问题描述】:

我想显示我手机中的所有照片,并使用毕加索在网格视图中显示它们。问题是我不知道如何实现。

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

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);

MediaStore.Images.Thumbnails.getThumbnail 获取缩略图的位图注入 ImageView。

我如何使用毕加索来实现它?

【问题讨论】:

    标签: android photos picasso


    【解决方案1】:

    很简单。只需使用 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);
    

    【讨论】:

    • 这将无法获得正确的缩略图,因为您提供了 columnIndex 作为要显示的图像的 ID。使用默认投影,列索引为 0,因此您只需获取媒体存储中的第一个缩略图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 2013-08-12
    • 2014-11-12
    • 2015-11-14
    • 2020-07-14
    • 1970-01-01
    相关资源
    最近更新 更多