glide icon indicating copy to clipboard operation
glide copied to clipboard

Request: add callback for when Glide got the metadata of the source image (resolution, mimetype,...)

Open AndroidDeveloperLB opened this issue 7 months ago • 0 comments

I use Glide this way:

Glide.with(applicationContext).asBitmap()
        .load(imageResId)
        .override(someWidth, someHeight)
        .diskCacheStrategy(DiskCacheStrategy.NONE)
        .addListener(object : RequestListener<Bitmap> {
            override fun onLoadFailed(e: GlideException?, model: Any?, target: com.bumptech.glide.request.target.Target<Bitmap?>, isFirstResource: Boolean): Boolean {
                return false
            }

            @WorkerThread
            override fun onResourceReady(bitmap: Bitmap, model: Any, target: Target<Bitmap?>?, dataSource: DataSource, isFirstResource: Boolean): Boolean {
                //do something with the image
                return true
            }
        }).submit()

Thing is, I also need to get the original size (AKA resolution, meaning width&height in pixels ) of the image, and maybe even the rest of the metadata (mimetype,...). I've noticed there are some questions/requests about it (examples here and also on StackOverflow, here), but I can't find one that actually covers it and "hooks" to what Glide does. It's important to use what Glide does because:

  1. Efficiency. No reason to decode what the image tells about itself twice.
  2. Glide supports plugins to handle images that Android doesn't support on various Android OS versions (AVIF, JPEGXL, etc...)

Can you please add a callback (or offer a change to onResourceReady) so that I could get the image original size (and maybe other metadata too) ? One that won't affect Glide globally, but just here in this call?

AndroidDeveloperLB avatar Apr 01 '25 08:04 AndroidDeveloperLB