有沒有什麼辦法可以將base64字符串轉換爲Android中的圖像?我在通過套接字連接的服務器的xml中接收到這個base64字符串。將base64字符串轉換爲Android中的圖像
6
A
回答
1
查看http://www.source-code.biz/base64coder/java/或其他任何將base64字符串轉換爲字節數組的示例,然後使用ImageIcon(byte[] imageData)
構造函數。
2
現在在Android中有Base64實用程序,但它們僅適用於Android OS 2.2。
0
無法獲得任何解決方案(即使在Stackoverflow上)後,我構建了一個插件,將Base64 PNG字符串轉換爲我共享的文件here。 希望有所幫助。
0
如果你想的base64字符串轉換爲圖像文件(例如.png格式等),並將其保存到某個文件夾,你可以使用此代碼:
byte[] btDataFile = Base64.decode(base64Image, Base64.DEFAULT);
String fileName = YOUR_FILE_NAME + ".png";
try {
File folder = new File(context.getExternalFilesDir("") + /PathToFile);
if(!folder.exists()){
folder.mkdirs();
}
File myFile = new File(folder.getAbsolutePath(), fileName);
myFile.createNewFile();
FileOutputStream osf = new FileOutputStream(myFile);
osf.write(btDataFile);
osf.flush();
osf.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
並確保您已在您的清單文件中給出了以下所需權限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
相關問題
- 1. 將png或jpg圖像轉換爲Android中的Base64字符串
- 2. 如何將base64字符串圖像轉換爲android中的blob?
- 3. 將Base64字符串轉換爲android中的圖像
- 4. 將base64字符串轉換爲Android中的圖像
- 5. 如何在Android中將Base64 Blob字符串轉換爲圖像?
- 6. Android - 將字符串轉換爲圖像
- 7. 如何將圖像轉換爲文件中的Base64字符串?
- 8. 使用Phonegap將圖像轉換爲iOS上的Base64字符串
- 9. 將base64字符串轉換爲與OpenCV兼容的圖像
- 10. 將圖像文件轉換爲base64使用javascript的字符串
- 11. 將ASW S3上的.tif圖像轉換爲base64字符串C#
- 12. 將base64字符串轉換爲位圖的Android代碼
- 13. Phonegap插件:如何將Base64字符串轉換爲Android中的PNG圖像
- 14. 如何將圖像從Picturebox(VB6中的圖像)轉換爲字符串(Base64)?
- 15. 如何將圖像轉換爲Base64字符串?
- 16. 使用Base64算法將圖像轉換爲字符串
- 17. 如何將Base64字符串轉換爲Png圖像Mvc5 C#?
- 18. JavaScript - 將數據base64字符串轉換爲圖像
- 19. React-Native:將圖像url轉換爲base64字符串
- 20. 如何將base64字符串轉換爲PIL圖像對象
- 21. 將圖像從ImageView轉換爲Base64字符串
- 22. Ionic 2 - 需要將圖像從url轉換爲base64字符串
- 23. 如何將base64字符串轉換爲圖像?
- 24. 使用javascript將base64字符串轉換爲圖像
- 25. 如何將base64字符串轉換爲圖像文件?
- 26. 將Base64字符串轉換爲圖像文件?
- 27. NodeJS將Base64字符串轉換爲jpeg圖像 - NodeJS或mysql
- 28. Android將位圖轉換爲Base64字符串問題
- 29. java將inputStream轉換爲base64字符串
- 30. 將base64字符串轉換爲X509 certifcate
可能重複的[如何將圖像轉換爲Base64字符串?](http://stackoverflow.com/questions/4830711/how-to-convert-一個圖像 - 到 - 的base64〜應變G) – 2012-07-09 10:19:38