图片Uri或file地址转bitmap

1.Uri转bitmap

//        if (t is Uri) { //t是图片的Uri
//            val uri: Uri = t
//            bitmap = MediaStore.Images.Media.getBitmap(this.contentResolver, uri)
//            LogUtils.e("uri is uri  :$t")
//        }

2.file转bitmap

//if (t is File) {   //t是file格式
//            val file: File = t
//            bitmap = BitmapFactory.decodeFile(file.toString())
//            LogUtils.e("uri is file :$t")
//        }

3.如果t是这种地址(String类型)

/storage/emulated/0/DCIM/20180509_141837516_f096d2deb069129b4f5adfe9abd2dc22.jpg

val file = File(t.toString())
bitmap = BitmapFactory.decodeFile(file.toString())

你可能感兴趣的:(Android开发)