网络图片url转为base64数据
public String GetImageBase64FromUrl(String imgURL) { byte[] data = null; String result = null; BufferedImage image = null; try { // 创建URL URL url = new URL(imgURL); image = ImageIO.read(url); // ImageIO.write(image, "jpg", new File("D:\\1.jpg")); // bufferImage->base64 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", outputStream); BASE64Encoder encoder = new BASE64Encoder(); result = encoder.encode(outputStream.toByteArray()); result = result.replaceAll("\r|\n", ""); /*BASE64Decoder decoder = new BASE64Decoder(); //Base64解码 byte[] b = decoder.decodeBuffer(result); for(int i=0;i<b.length;++i) { if(b[i]<0) {//调整异常数据 b[i]+=256; } } //生成jpeg图片 String imgFilePath = "d://222.jpg";//新生成的图片 OutputStream out = new FileOutputStream(imgFilePath); out.write(b); out.flush(); out.close();*/ } catch (Exception e) { LogUtils.logException(e); } return result; }