简体   繁体   English

在Android应用中从大图片中提取和使用图像缩略图

[英]Extracting and using Image Thumbnail from larger picture in android app

I'am working on a project and I need to create an interface such that a larresge number of picture are visible to user in a Thumbnail version and when the user clicks the Thumbnail original picture pops up. 我正在做一个项目,我需要创建一个界面,以便在缩略图版本中用户可以看到较大数量的图片,并且当用户单击缩略图时,原始图片会弹出。 When I use the original pictures in a bound ImageView (say layout_width and layout_height of 100 dp each) then the app is crashing. 当我在绑定的ImageView中使用原始图片(比如说layout_width和layout_height分别为100 dp)时,应用崩溃了。 I have the res id ( R.drawable.imageID ) of the original images. 我有原始图像的res id( R.drawable.imageID )。 So is there a way through coding such that my app does not crash and show Images in thumbnail size and also keep the original image or I will have to load resized smaller images to the res directory of the app?? 那么有没有一种编码方法,这样我的应用程序不会崩溃并以缩略图显示图像,并且还保留原始图像,否则我将不得不将调整大小的较小图像加载到应用程序的res目录中? What is the coding way to get res id to Thumbnails of original Images?? 将res id转换为原始图像缩略图的编码方式是什么?

You should use Glide to handle it for you. 您应该使用Glide为您处理它。

For thumbnails you can use code like below: 对于缩略图,您可以使用如下代码:

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

And when you want to load the full Image 而当您想加载完整图像时

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

'this' refers to Activity or Fragment instance “ this”是指Activity或Fragment实例

'.thumbail(0.2f)' is the percentage reduce that you want to do “ .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." “例如,如果您传递0.1f作为参数,则Glide将显示缩小到原始尺寸10%的原始图像。” https://futurestud.io/blog/glide-thumbnails https://futurestud.io/blog/glide-thumbnails

You must have attention to Glide Module configuration to a best Image Resolution on full image. 您必须注意滑翔模块的配置,以在完整图像上获得最佳图像分辨率。

https://github.com/bumptech/glide https://github.com/bumptech/glide

**Using Glide you dont need to create two images =) **使用Glide,您无需创建两个图像=)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM