从乌里转换位图返回null [英] Converting bitmap from Uri is returning null

查看:188
本文介绍了从乌里转换位图返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我已经使用谷歌驱动器来接图像和文件,文件我的code为正常使用的大部分时间。不幸的是在某些情况下,图像导入不工作,像位图返回空值,下面是我已经习惯了内容URI转换为输入流和位图的code。

In my android application I have used Google drive to pick images and files, for files my code is working perfectly most of the time. Unfortunately in some cases image import is not working, image bitmap is returning null value, below is the code which I have used to convert content URI to input stream and bitmap.

Bitmap bitmap = null;
InputStream input = null;
try {
    input = getActivity()
        .getContentResolver()
        .openInputStream(
            Uri.parse("content://com.google.android.apps.docs.storage/document/acc%3D2%3Bdoc%3D83"));

    Log.Logger()
        .finest("Profileimagefile Fragment Drive called input" + input);

    bitmap = BitmapFactory
        .decodeStream(input);
} catch (FileNotFoundException e) {

    e.printStackTrace();
}

我刚才提到的URI,这是不工作的,请帮我找出这个问题。

I have mentioned the URI which is not working, kindly help me to figure out the issue.

推荐答案

尝试了这一点,以从获得的位图:

Try this out to get the bitmap from an:

Uri sArtworkUri = Uri
    .parse("content://com.google.android.apps.docs.storage/document/acc%3D2%3Bdoc%3D83");
Uri uris = ContentUris.withAppendedId(sArtworkUri,
    Long.parseLong(fileUri));

ContentResolver res = getContentResolver();
InputStream in = null;
try { in = res.openInputStream(uris);
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Bitmap artwork = BitmapFactory.decodeStream( in );

使用这件作品....

Use this artwork ....

这篇关于从乌里转换位图返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆