图片转base64(注意:转换后的字符串需要加上"data:image/png;base64," 才能被识别)
// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
public static String GetImageStr(String imagePath) {
InputStream in = null;
byte[] data = null;// 读取图片字节数组
try {
imagePath=saveImgPath+"/"+imagePath;
in = new FileInputStream(imagePath);
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
e.printStackTrace();

该博客介绍了如何将图片转换为base64字符串以及将base64字符串还原为图片,同时提供了计算base64图片大小的方法。此外,还提及了日志输出的使用。
最低0.47元/天 解锁文章





