的base64图像数据转换为图像文件(.PNG),并将其保存到本地文件系统 [英] Convert base64 image data to an image file(.png) and save it to Local file system
本文介绍了的base64图像数据转换为图像文件(.PNG),并将其保存到本地文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以base64格式的图像数据,我想这样的base64字符串,图片(.png)文件转换和保存文件下载到本地文件系统,在我的Android应用程序。请建议我一个解决方案
I am having Image data in base64 format, I want to convert this base64 string to image(.PNG) file and save that file to Local file system in my android application. Please suggest a solution for me
推荐答案
试试这个。
FileOutputStream fos = null;
try {
if (base64ImageData != null) {
fos = context.openFileOutput("imageName.png", Context.MODE_PRIVATE);
byte[] decodedString = android.util.Base64.decode(base64ImageData, android.util.Base64.DEFAULT);
fos.write(decodedString);
fos.flush();
fos.close();
}
} catch (Exception e) {
} finally {
if (fos != null) {
fos = null;
}
}
这篇关于的base64图像数据转换为图像文件(.PNG),并将其保存到本地文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文