java网络图片转base64编码


public static String encodeImgageToBase64(String remark) {

ByteArrayOutputStream outputStream = null;

try {

URL url = new URL(remark);

BufferedImage bufferedImage = ImageIO.read(url);

outputStream = new ByteArrayOutputStream();

ImageIO.write(bufferedImage,"jpg",outputStream);

} catch (IOException e) {

LogUtils.logInfo("图片下载失败");

LogUtils.logException(e);

return remark;

}

BASE64Encoder encoder = new BASE64Encoder();

String s= encoder.encode(outputStream.toByteArray());

//s = s.replaceAll("\\r\\n","");

//return encoder.encode(outputStream.toByteArray());// 返回Base64编码过的字节数组字符串

return s;

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM