3
我想將圖像以Base64格式字符串發佈到Web服務器。我需要從網絡服務器取回它並以位圖格式解碼它,以便我可以在listview中顯示圖像。但是在解碼時出現錯誤。 請看看我在這裏發佈的代碼..如何解碼來自json對象的圖像?
編碼:
ByteArrayOutputStream byteArrayBitmapStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, COMPRESSION_QUALITY, byteArrayBitmapStream);
byte[] b = byteArrayBitmapStream.toByteArray();
String encodedImage = MyBase64.encode(b);
解碼:
byte[] byteArray = Base64.decode(jsonObject.getString("imageData"), Base64.DEFAULT) ;
System.out.println("byte[]:"+byteArray);
Bitmap bmp1 = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
這裏是日誌:[錯誤的logcat顯示]
12-12 06:09:12.243: E/BitmapFactory(1037): Unable to decode stream: java.io.FileNotFoundException: /[email protected]: open failed: ENOENT (No such file or directory)
12-12 06:09:12.243: I/System.out(1037): resolveUri failed on bad bitmap uri: [email protected]
12-12 06:09:12.313: E/BitmapFactory(1037): Unable to decode stream: java.io.FileNotFoundException: /[email protected]: open failed: ENOENT (No such file or directory)
12-12 06:09:12.313: I/System.out(1037): resolveUri failed on bad bitmap uri: [email protected]
12-12 06:09:12.393: E/BitmapFactory(1037): Unable to decode stream: java.io.FileNotFoundException: /[email protected]: open failed: ENOENT (No such file or directory)
12-12 06:09:12.393: I/System.out(1037): resolveUri failed on bad bitmap uri: [email protected]
12-12 06:09:12.473: E/BitmapFactory(1037): Unable to decode stream: java.io.FileNotFoundException: /[email protected]: open failed: ENOENT (No such file or directory)
12-12 06:09:12.473: I/System.out(1037): resolveUri failed on bad bitmap uri: [email protected]
12-12 06:09:12.533: E/BitmapFactory(1037): Unable to decode stream: java.io.FileNotFoundException: /[email protected]: open failed: ENOENT (No such file or directory)
12-12 06:09:12.533: I/System.out(1037): resolveUri failed on bad bitmap uri: [email protected]
12-12 06:09:12.613: E/BitmapFactory(1037): Unable to decode stream: java.io.FileNotFoundException: /[email protected]: open failed: ENOENT (No such file or directory)
12-12 06:09:12.613: I/System.out(1037): resolveUri failed on bad bitmap uri: [email protected]
此鏈接是有用的http://stackoverflow.com/questions/19767615/how-to-display-image-byte-array-from-json-into-imageview-factory-returns-nu –
你在解碼或編碼時遇到這個錯誤? –
@ M-WaJeEh解碼時出現此錯誤,請幫我解決。 – user2879697