android - 从 uri 中检索位图

标签 android android-bitmap

我已包含“通过 myApp 共享”选项。我在接收 Activity 类中插入了以下代码。

    // Get the intent that started this activity
    Intent intent = getIntent();
    Uri data = intent.getData();

    // Figure out what to do based on the intent type
    if (intent.getType().indexOf("image/") != -1) {
        // Handle intents with image data ...
}

检索位图图像的下一步是什么。

最佳答案

因为你已经得到了 Uri。现在您必须在 getBitmap() 中传递该 Uri 以获取位图并使用该位图。

Uri imageUri = intent.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),imageUri);
Imageview my_img_view = (Imageview ) findViewById (R.id.my_img_view);
my_img_view.setImageBitmap(bitmap);

关于android - 从 uri 中检索位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20782713/

相关文章:

java - 添加到 Canvas 时显示蓝色的位图 (android studio)

java - 适配器不会更新

android - 禁止点击整个 RecyclerView

java - 使用 EventKey 在 EditText 上设置文本

java - 在Android中使用canvas和位图绘制8x8的正方形

android - BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions) 返回 FileNotFoundException

android - 如何使用 ByteBuffer(无颜色校正)获取 RGB 位图?

java - Android canvas 不在我的位图上绘制文本

java - 使用 Jsoup 解析 Html 内容

android - 在uploadArchives任务中用版本控制的 Artifact 替换项目依赖项