【问题标题】:converting image to bitmap in android在android中将图像转换为位图
【发布时间】:2020-09-15 10:54:04
【问题描述】:

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

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

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

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

【问题讨论】:

标签: android bitmap


【解决方案1】:

使用此代码

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

【讨论】:

  • 太棒了,很高兴你发布了这个。
【解决方案2】:
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uri);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(bitmap);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-30
    • 2017-02-01
    • 1970-01-01
    • 2017-08-21
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    • 1970-01-01
    相关资源
    最近更新 更多