在android中将图像转换为位图

时间:2011-08-04 06:10:15

标签: android bitmap

我想从手机的SD卡中选择一张图片。我使用下面的代码来选择并在我的活动中显示

Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
Uri uri = Uri.parse(selectedImagePath);
uploadimage.setImageURI(uri);

它工作正常,但我想将此图像转换为Bitmap,我有图像路径和URI。

在这种情况下如何将图像转换为位图?请帮助我,提前谢谢。

2 个答案:

答案 0 :(得分:20)

使用此代码

Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));

答案 1 :(得分:0)

Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uri);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(bitmap);
相关问题