/** * base64字符串转化成图片 * @param imgData base64图片编码 * @param imgFilePath 存放到本地路径 * @return * @throws IOException */ public static boolean generateImage(String imgData, String imgFilePath) throws IOException { // 对字节数组字符串进行Base64解码并生成图片 if (imgData == null) { return false; } BASE64Decoder decoder = new BASE64Decoder(); OutputStream out = null; try { out = new FileOutputStream(imgFilePath); // Base64解码 byte[] b = decoder.decodeBuffer(imgData); for (int i = 0; i < b.length; ++i) { if (b[i] < 0) { b[i] += 256; } } out.write(b); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { out.flush(); out.close(); return true; } }
08-19
3157
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-17
975
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-20
1070
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-15
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交