我正在处理一个项目,我需要创建一个界面,以便在缩略图版本中用户可以看到大量图片,并且当用户单击缩略图原始图片时会弹出。
当我在绑定(bind)的 ImageView 中使用原始图片时(比如 layout_width 和 layout_height 各为 100 dp),应用程序崩溃了。
我有原始图像的 res id (R.drawable.imageID
)。
那么有没有一种方法可以通过编码使我的应用程序不会崩溃并以缩略图大小显示图像并保留原始图像,否则我将不得不将调整大小的较小图像加载到应用程序的 res 目录中?
获取原始图像缩略图的res id的编码方式是什么?
最佳答案
你应该使用 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)' 是您要减少的百分比
"For example, if you pass 0.1f as the parameter, Glide will display the original image reduced to 10% of the size." https://futurestud.io/blog/glide-thumbnails
您必须注意 Glide Module 配置以在完整图像上获得最佳图像分辨率。
https://github.com/bumptech/glide
**使用 Glide 你不需要创建两个图像 =)
关于java - 从android应用程序中的大图片中提取和使用图像缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36434381/