AiJiNanProject/src/test/java/com/platform/QrCodeTest.java

28 lines
990 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import com.platform.modules.live.utils.QrCodeUtils;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class QrCodeTest {
public static void main(String[] args) {
try {
// 二维码内容
String content = "http://www.jay99.cn";
// Logo路径相对于类路径
String logoPath = "http://cdn.jay99.cn/logo.png";
// 是否压缩Logo
boolean needCompress = true;
// 生成二维码图片
BufferedImage qrImage = QrCodeUtils.createImage(content, logoPath, needCompress);
// 保存二维码图片到文件
File outputFile = new File("qrcode.png");
ImageIO.write(qrImage, "png", outputFile);
System.out.println("二维码生成成功,保存到 " + outputFile.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
}
}
}