首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从uri中检索位图

从uri中检索位图
EN

Stack Overflow用户
提问于 2013-12-26 17:54:52
回答 8查看 87.6K关注 0票数 19

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

代码语言:javascript
复制
    // 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 ...
}

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

EN

回答 8

Stack Overflow用户

发布于 2013-12-26 18:05:53

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

代码语言:javascript
复制
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);
票数 40
EN

Stack Overflow用户

发布于 2013-12-26 18:00:15

为了从uri获取位图,

代码语言:javascript
复制
Bitmap  mBitmap = Media.getBitmap(this.getContentResolver(), uri);

希望这对你有帮助。

票数 9
EN

Stack Overflow用户

发布于 2017-03-03 13:09:55

代码语言:javascript
复制
Retrive bitmap from uri.....

public static Bitmap decodeUriToBitmap(Context mContext, Uri sendUri) {
        Bitmap getBitmap = null;
        try {
            InputStream image_stream;
            try {
                image_stream = mContext.getContentResolver().openInputStream(sendUri);
                getBitmap = BitmapFactory.decodeStream(image_stream);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getBitmap;
    }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20782713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档