glide icon indicating copy to clipboard operation
glide copied to clipboard

How to monitor the original image size?

Open GentlemanHao opened this issue 3 years ago • 0 comments

I have a new question: We know that Glide will compress the image according to the ImageView size, this is a great feature and I need it. But I want to record the original size of the web picture.

This is my code.

//on my device, 480px * 480px
<ImageView
   android:id="@+id/iv_icon"
   android:layout_width="160dp"
   android:layout_height="160dp" />
 val icon = findViewById<ImageView>(R.id.iv_icon) //480px * 480px
 // 1250px * 540px
 val imageUrl = "https://upload.jianshu.io/admin_banners/web_images/5055/348f9e194f4062a17f587e2963b7feb0b0a5a982.png"

//1. use SimpleTarget way, Get the size of the original image, uncompressed.
Glide.with(this).load(imageUrl).asBitmap().into(object : SimpleTarget<Bitmap>() {
                override fun onResourceReady(bitmap: Bitmap?, p1: GlideAnimation<in Bitmap>?) {
                    Log.d("--wh--", "bitmap: ${bitmap?.width} ${bitmap?.height}")  //print 1250  540
                    icon.setImageBitmap(bitmap)
                }
            })

//2. use RequestListener way, Get compressed image
Glide.with(this).load(imageUrl).listener(object : RequestListener<String, GlideDrawable> {
                override fun onException(e: Exception?, model: String?, target: Target<GlideDrawable>?, isFirstResource: Boolean): Boolean {
                    return false
                }

                override fun onResourceReady(glideDrawable: GlideDrawable?, model: String?, target: Target<GlideDrawable>?, isFromMemory: Boolean, isFirstResource: Boolean): Boolean {
                    // print 480  207, Compressed according to ImageView size.
                    Log.d("--wh--", "Glide onResourceReady: glideDrawable: $glideDrawable  ${glideDrawable?.intrinsicWidth}  ${glideDrawable?.intrinsicHeight}") 
                    return false
                }

            }).into(icon)

Both methods can't meet my needs, I want Glide to compress the picture, but also want to get the original picture size for record, I am using version 3.7.0, I will upgrade if necessary, please help me. Thank you!

@TWiStErRob

Originally posted by @GentlemanHao in https://github.com/bumptech/glide/issues/781#issuecomment-1204676523

GentlemanHao avatar Aug 04 '22 03:08 GentlemanHao