BufferedImage转Base64编码方法封装(JAVA版)
该方法可以将BufferedImage格式转Base64编码。
/**
* BufferedImage转base64
* @param bufferedImage
* @return
*/
public String bufferedImageToBase64(BufferedImage bufferedImage) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
// 设置图片格式
ImageIO.write(bufferedImage, "jpg", stream);
} catch (IOException e) {
e.printStackTrace();
}
byte[] bytes = Base64.encodeBase64(stream.toByteArray());
String base64 = new String(bytes);
return "data:image/jpeg;base64," + base64;
}