我正在創建一個需要在內部存儲中存儲一些多媒體文件的 Android 應用程序。用戶可以從選擇器中選擇該多媒體文件。即使用戶刪除這些文件,這些文件也必須可用,因此它們會被復制到內部存儲中。這是我的代碼:final Bitmap bitm = MediaStore.Images.Media.getBitmap( this.getContentResolver(), uri );final int bitmapRawLength = bitm.getAllocationByteCount();final ByteBuffer byteBuffer = ByteBuffer.allocate( bitmapRawLength );bitm.copyPixelsToBuffer( byteBuffer );data = byteBuffer.array();final ByteArrayInputStream in = new ByteArrayInputStream( data );db.store( in );因此,組成圖像的字節通過InputStream復制到內部存儲中的普通文件中。顯然它有效,因為文件有內容。稍后將圖像加載到ImageView 中:private void loadImage(File imgFile){ if ( imgFile.exists() ) { final Bitmap bitmap = BitmapFactory.decodeFile( mediaFile.getPath() ); this.ivPictureBox.setImageBitmap( bitmap ); } else { this.abortDueToMissingFile( imgFile ); } return;}不幸的是,這不起作用。當需要加載該圖像時,ImageView變為空白,不顯示任何內容。實際上,在日志中會出現以下消息:D/skia: --- Failed to create image decoder with message 'unimplemented'如果我在 Android Studio 中使用文件資源管理器并將圖像導出到我的計算機,則 GwenView 會失敗并顯示消息“無法加載元數據”。我怎樣才能正確地存儲帶有完整信息的圖像,或者正確地顯示它,無論哪種更容易或可行?
2 回答

30秒到達戰場
TA貢獻1828條經驗 獲得超6個贊
愚蠢的我!
這很簡單:
final InputStream in = this.getContentResolver().openInputStream( uri );
...并隨心所欲地復制它。
這適用于具有 SCHEME_CONTENT 和 SCHEME_FILE 方案的 URI。
添加回答
舉報
0/150
提交
取消