Base64图片字符串生成本地图片

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;

public static void generateImage(String imgStr, String path) { try { byte[] b = Base64.decodeBase64(new String(imgStr).getBytes()); for (int i = 0; i < b.length; ++i) { if (b[i] < 0) {//调整异常数据 b[i] += 256; } } String imgFilePath = path;//新生成的图片 OutputStream out = new FileOutputStream(imgFilePath); out.write(b); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } }

 

posted @ 2019-10-15 10:46  Wang·MY  阅读(293)  评论(0编辑  收藏  举报