简体   繁体   中英

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. I have the res id ( R.drawable.imageID ) of the original images. 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?? What is the coding way to get res id to Thumbnails of original Images??

You should use Glide to handle it for you.

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

'.thumbail(0.2f)' is the percentage reduce that you want to do

"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

You must have attention to Glide Module configuration to a best Image Resolution on full image.

https://github.com/bumptech/glide

**Using Glide you dont need to create two images =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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