【问题标题】:Extracting and using Image Thumbnail from larger picture in android app从Android应用程序中的较大图片中提取和使用图像缩略图
【发布时间】:2016-07-25 20:49:11
【问题描述】:

我正在做一个项目,我需要创建一个界面,以便用户可以在缩略图版本中看到大量图片,并且当用户单击缩略图时会弹出原始图片。 当我在绑定的 ImageView 中使用原始图片(比如 layout_width 和 layout_height 各 100 dp)时,应用程序崩溃了。 我有原始图像的 res id (R.drawable.imageID)。 那么有没有办法通过编码使我的应用程序不会崩溃并以缩略图大小显示图像并保留原始图像,否则我将不得不将调整大小的较小图像加载到应用程序的 res 目录中? 获取原始图像缩略图的res id的编码方式是什么?

【问题讨论】:

    标签: java android image android-studio thumbnails


    【解决方案1】:

    您应该使用 Glide 来为您处理。

    对于缩略图,您可以使用如下代码:

    Glide.with(this)
         .load(your_path)
         .thumbnail(0.2f)
         .into(imageview);
    

    当你想要加载完整的图片时

    Glide.with(this)
          .load(your_path)
          .asBitmap()
          .into(imageView);
    

    'this' 指的是 Activity 或 Fragment 实例

    '.thumbail(0.2f)' 是你想要减少的百分比

    "例如传入0.1f作为参数,Glide会显示 原始图像缩小到 10% 的大小。” https://futurestud.io/blog/glide-thumbnails

    您必须注意 Glide Module 配置以在完整图像上获得最佳图像分辨率。

    https://github.com/bumptech/glide

    **使用 Glide 你不需要创建两个图像 =)

    【讨论】:

    • 我不认为这是正确的,当您使用 thumbnail() 时,会加载缩略图,但在后台也会下载完整的图像,然后缩略图会被完整的图像替换,所以是必要的两张图片,全图和小缩略图
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 2012-08-29
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多