2016-11-08 29 views
3

我最近更新adobecreativesdk與最新版本,以支持Android Nougat。之後,我在編輯器中編輯圖片我嘗試使用下面的代碼來獲得編輯的位圖onActivityResult:BitmapFactory.decodeFile()不支持AdobeImageIntent.EXTRA_OUTPUT_URI

mImageUri = data.getParcelableExtra(AdobeImageIntent.EXTRA_OUTPUT_URI); 

        Bitmap bitmap = BitmapFactory.decodeFile(mImageUri.getPath()); 

        if(bitmap!=null) 
        { 

        ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
        imagebytes = baos.toByteArray(); 

        PlayAnimation(); 
        } 

之前更新到我用data.getData(最新版本),而不是data.getParcelableExtra它Android棉花糖工作正常。但是現在我的位圖總是返回爲null。我已經設置了圖像的URI,就像它在本文中提到的一樣: https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en。我也嘗試使用BitmapFactory.Options調整位圖的大小,因爲可能圖像太大。但似乎並非如此。

+0

'mImageUri.getPath()'。請告訴路徑。它可能是內容的一部分。 – greenapps

回答

1

如果你有Uri圖像最好是通過ContentResolver來閱讀:

Uri uri; 
Context context; 
try { 
    Bitmap bm = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri)); 
} catch (FileNotFoundException e) { 
    e.printStackTrace(); 
} 

ContentResolver爲您處理底層存儲差異。它與file://,content://和其他Uri類型都可以正常工作。

+0

是的,這解決了問題:)謝謝 – nexus