从 android 应用中的大图片中提取和使用图像缩略图
Extracting and using Image Thumbnail from larger picture in android app
我正在处理一个项目,我需要创建一个界面,以便在缩略图版本中用户可以看到大量图片,并且当用户单击缩略图时会弹出原始图片。
当我在绑定的 ImageView 中使用原始图片时(比如 layout_width 和 layout_height 每个 100 dp)然后应用程序崩溃。
我有原始图像的 res id (R.drawable.imageID
)。
那么有没有一种方法可以通过编码使我的应用程序不会崩溃并以缩略图大小显示图像并保留原始图像,否则我将不得不将调整大小的较小图像加载到应用程序的 res 目录中?
获取原图缩略图resid的编码方式是什么?
你应该使用 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 模块配置为全图的最佳图像分辨率。
https://github.com/bumptech/glide
**使用 Glide 你不需要创建两个图像 =)
我正在处理一个项目,我需要创建一个界面,以便在缩略图版本中用户可以看到大量图片,并且当用户单击缩略图时会弹出原始图片。
当我在绑定的 ImageView 中使用原始图片时(比如 layout_width 和 layout_height 每个 100 dp)然后应用程序崩溃。
我有原始图像的 res id (R.drawable.imageID
)。
那么有没有一种方法可以通过编码使我的应用程序不会崩溃并以缩略图大小显示图像并保留原始图像,否则我将不得不将调整大小的较小图像加载到应用程序的 res 目录中?
获取原图缩略图resid的编码方式是什么?
你应该使用 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 模块配置为全图的最佳图像分辨率。
https://github.com/bumptech/glide
**使用 Glide 你不需要创建两个图像 =)