简体   繁体   中英

Android Image setImageBitmap not working when using glide load image

I have a problem using Glide load image android.I will present it simply as follows: First I load image using glide I want to choose image using Intent.ACTION_PICK but when I using image.setImageBitmap on onActivityResult but it not working

Glide.with(context!!).load(url).centerCrop().error(R.drawable.avata_boy).into(imgAvata)

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == PICK_IMAGE_REQUEST && resultCode == Activity.RESULT_OK
        && data != null && data.data != null
    ) {
        filePath = data.data
        try {
            val bitmap = BitmapFactory.decodeStream(activity!!.contentResolver.openInputStream(filePath!!))
             imgAvata.setImageBitmap(bitmap)
            Glide.with(context!!)
                .load(bitmap)
                .placeholder(R.drawable.avata_boy)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .skipMemoryCache(true)
                .into(imgAvata)

        } catch (e: IOException) {
        }

Try this!!

val myBitmap = BitmapFactory.decodeFile(filePath!!.getAbsolutePath())

            imgview.setImageBitmap(myBitmap)

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