Java:将图片转换成Base64编码

将图片转换成Base64编码

//参数imgFile:图片完整路径
public static String getImgBase64Str(String imgFile) {
        // 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
        InputStream in = null;
        byte[] data = null;
        // 读取图片字节数组
        try {
            in = new FileInputStream(imgFile);
            data = new byte[in.available()];
            in.read(data);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Base64.encodeBase64String(data);
    }
原文地址:https://www.cnblogs.com/lizm166/p/15788518.html