从乌里转换位图返回null位图、null

2023-09-03 21:47:30 作者:若無心,何必在意

在我的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 ....

 
精彩推荐