/**
* 将图片转换为base64格式
*
* @param imageUrl:图片路径
* @param sizeLimit:原图大小上限,当图片原图大小超过该值时先将图片大小 设置为该值以下再转换成base64格式,单位kb
* @return
*/
public static String convertImageToBase64(String imageUrl, Integer sizeLimit) throws IOException {
//默认上限为500k
if (sizeLimit == null) {
sizeLimit = 500;
}
sizeLimit = sizeLimit * 1024;
String base64Image;
DataInputStream dataInputStream = null;
ByteArrayOutputStream outputStream = null;
ByteArrayInputStream inputStream = null;
try {
//从远程读取图片
URL url = new URL(imageUrl);
dataInputStream = new DataInputStream(url.openStream());
outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[2048];
int length;
while ((length = dataInput