0

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) {
        }
Zoe
  • 27,060
  • 21
  • 118
  • 148
  • You don't have to do "decodeStream" the bitmap. Glide will automatically do it for you. Glide.with(context!!).load(filePath).into(imgAvata); Now let's discuss the actual problem, is it throwing any error?? Did you check the filePath?? is it null?? – Sujith Niraikulathan Mar 29 '19 at 09:12
  • if I remove load image by Glide first on onCreate. imgAvata.setImageBitmap(bitmap) working. But i load image by glide first it not working – Hoi Nguyen Xuan Mar 29 '19 at 17:00
  • But you are getting image location on onActivityResult. I believe you are saying that glide is not working with the path given by "onActivityResult" intent data, right? – Sujith Niraikulathan Mar 30 '19 at 07:27

1 Answers1

0

Try this!!

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

            imgview.setImageBitmap(myBitmap)
Urvish Jani
  • 104
  • 1
  • 4