Is there a way to load image as bitmap to Glide

后端 未结 11 1456
温柔的废话
温柔的废话 2020-12-04 19:35

Im looking for a way to use bitmap as input to Glide. I am even not sure if its possible. It\'s for resizing purposes. Glide has a good image enhancement with scale. The pro

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 20:15

    In Kotlin,

    Glide.with(this)
                .asBitmap()
                .load("https://...")
                .addListener(object : RequestListener {
                    override fun onLoadFailed(
                        e: GlideException?,
                        model: Any?,
                        target: Target?,
                        isFirstResource: Boolean
                    ): Boolean {
                        Toast.makeText(this@MainActivity, "failed: " + e?.printStackTrace(), Toast.LENGTH_SHORT).show()
                        return false
                    }
    
                    override fun onResourceReady(
                        resource: Bitmap?,
                        model: Any?,
                        target: Target?,
                        dataSource: DataSource?,
                        isFirstResource: Boolean
                    ): Boolean {
                        //image is ready, you can get bitmap here
                        return false
                    }
    
                })
                .into(imageView)
    

提交回复
热议问题