网上的转换方式基本都是下面这种,但我转换后就是损坏。
BASE64Decoder decoder = new BASE64Decoder(); //Base64解码 byte[] b = decoder.decodeBuffer(imgfnPhoto); for (int i = 0; i < b.length; ++i) { if (b[i] < 0) {// 调整异常数据 b[i] += 256; } } //生成jpg图片 String filename = this.createGUIDService.getGUID()+".jpg"; OutputStream out = new FileOutputStream(request.getRealPath("fsweb/workData/web") + "//" + filename); out.write(b); out.flush(); out.close();
改为下面的方式可以成功。
public static void tr(String imageString){ BufferedImage image = null; byte[] imageByte = null; try { imageByte = DatatypeConverter.parseBase64Binary(imageString); ByteArrayInputStream bis = new ByteArrayInputStream(imageByte); image = ImageIO.read(new ByteArrayInputStream(imageByte)); bis.close(); File outputfile = new File("e:\\sealImg.bmp"); ImageIO.write(image, "bmp", outputfile); } catch (IOException e) { e.printStackTrace(); } }
小鱼儿 2019-07-07
白诗秀儿 2019-07-09
伍仔 2016-03-03
白诗秀儿 2016-05-30
冰雪魔女 2021-02-05
沙落雁 2016-06-25
吟风 2019-07-10
早安 2020-07-23
寒江独钓 2017-10-27
白诗秀儿 2016-02-19