标签:data www 转化 exception tostring ase org height llb
import cn.hutool.extra.qrcode.QrCodeUtil; // 生成链接 String url = longUrl(inviteId, inviteDetailId, EMAIL_SEND_TYPE, CLICK_OPERATION); String path = newFile.getAbsolutePath() + inviteDetail.getInviteId() + "-" + i + ".jpg"; File generate = QrCodeUtil.generate(url, 300, 300, FileUtil.file(path)); String base64Image = encryptFileToBase64(path); urlList.add(url); qrCodeUrl.add(base64Image);
将图片进行转化编码格式
private static String encryptFileToBase64(String filePath) { if (filePath == null) { return null; } File file = new File(filePath); if (!file.isFile()) { return null; } try { byte[] b = Files.readAllBytes(Paths.get(filePath)); return java.util.Base64.getEncoder().encodeToString(b); } catch (IOException e) { e.printStackTrace(); } return null; }
<html lang="en" xmlns:th="http://www.thymeleaf.org"> ---------------------------------------------------------------- <p th:each="emailVo,start:${list}"> <span th:each="qrCodeUrl,startQR:${start.current.qrCodeUrl}"> <img th:src="‘data:image/jpg;base64,‘+${qrCodeUrl}" style="height: 120px;width: 120px"/> <span th:text="${startQR.count}"></span>.jpg </span> </p>
Java将图片转化为base64编码并且通过thymeleaf将图片在页面展示
标签:data www 转化 exception tostring ase org height llb
原文地址:https://www.cnblogs.com/slAmor/p/13053645.html