【问题标题】:Converting bitmap from Uri is returning null [duplicate]从 Uri 转换位图返回 null [重复]
【发布时间】:2015-05-13 05:36:43
【问题描述】:

在我的 android 应用程序中,我使用 Google 驱动器来挑选图像和文件,因为我的代码大部分时间都可以正常工作。不幸的是,在某些情况下图像导入不起作用,图像位图返回空值,下面是我用来将内容 URI 转换为输入流和位图的代码。

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 不起作用,请帮助我找出问题所在。

【问题讨论】:

    标签: android image google-drive-api


    【解决方案1】:

    试试这个从以下位置获取位图:

    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 );
    

    使用这幅作品....

    【讨论】:

    • 我没有文件 uri ??究竟是什么意思??
    • @快速学习者这里的'fileUri'是什么?请回复
    猜你喜欢
    • 1970-01-01
    • 2018-02-23
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-16
    • 1970-01-01
    相关资源
    最近更新 更多