替代的阿卡什Kurian说何塞答案
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
我始终使用
fun getBitmap(file: Uri, cr: ContentResolver): Bitmap?{
var bitmap: Bitmap ?= null
try {
val inputStream = cr.openInputStream(file)
bitmap = BitmapFactory.decodeStream(inputStream)
// close stream
try {
inputStream.close()
} catch (e: IOException) {
e.printStackTrace()
}
}catch (e: FileNotFoundException){}
return bitmap
}
它同时适用从画廊的照片和照相机的照片。
它
更大的问题:使用这种方法Picasso unable to display image from Gallery
开画廊:
private void openGallery(){
if (Build.VERSION.SDK_INT <19){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, getResources().getString(R.string.select_picture)),GALLERY_INTENT_CALLED);
} else {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, GALLERY_KITKAT_INTENT_CALLED);
}
}
那你就能够读取转换乌里到位图使用afromentioned ContentResolver.openInputStream
或设置图片ImageView.setImageUri(Uri)
你能得到图像路径吗? –