28 lines
990 B
Java
28 lines
990 B
Java
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();
|
||
}
|
||
}
|
||
}
|