How to get Bitmap from an Uri?

前端 未结 16 1279
时光说笑
时光说笑 2020-11-22 10:41

How to get a Bitmap object from an Uri (if I succeed to store it in /data/data/MYFOLDER/myimage.png or file///data/data/MYFOLDER/myimage.png) to u

16条回答
  •  醉梦人生
    2020-11-22 10:47

    (KOTLIN) So, as of April 7th, 2020 none of the above mentioned options worked, but here's what worked for me:

    1. If you want to store the bitmap in a val and set an imageView with it, use this:

      val bitmap = BitmapFactory.decodeFile(currentPhotoPath).also { bitmap -> imageView.setImageBitmap(bitmap) }

    2. If you just want to set the bitmap to and imageView, use this:

      BitmapFactory.decodeFile(currentPhotoPath).also { bitmap -> imageView.setImageBitmap(bitmap) }

提交回复
热议问题