Commit 7e120bd0 by caiyt

修改二维码尺寸生成逻辑

parent af4d8834
...@@ -17,7 +17,7 @@ import java.util.Hashtable; ...@@ -17,7 +17,7 @@ import java.util.Hashtable;
public class QRCodeUtil { public class QRCodeUtil {
private static int onColor = 0xFF000000; //前景色 private static int onColor = 0xFF000000; //前景色
private static int offColor = 0xFFFFFFFF; //背景色 private static int offColor = 0xFFFFFFFF; //背景色
private static int margin = 1; //白边大小,取值范围0~4 private static int margin = 0; //白边大小,取值范围0~4
private static ErrorCorrectionLevel level = ErrorCorrectionLevel.L; //二维码容错率 private static ErrorCorrectionLevel level = ErrorCorrectionLevel.L; //二维码容错率
/** /**
...@@ -34,15 +34,20 @@ public class QRCodeUtil { ...@@ -34,15 +34,20 @@ public class QRCodeUtil {
hints.put(EncodeHintType.MARGIN, margin); //设置白边 hints.put(EncodeHintType.MARGIN, margin); //设置白边
try { try {
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints);
bitMatrix = deleteWhite(bitMatrix); // bitMatrix = deleteWhite(bitMatrix);
BufferedImage image = toBufferedImage(bitMatrix); BufferedImage image = toBufferedImage(bitMatrix);
// MatrixToImageWriter.writeToStream(bitMatrix, format, byteArrayOutputStream, config); // MatrixToImageWriter.writeToStream(bitMatrix, format, byteArrayOutputStream, config);
ImageIO.write(image, format, byteArrayOutputStream); //生成二维码图片 ImageIO.write(image, format, byteArrayOutputStream); //生成二维码图片
// ImageIO.write(image, format, new File("C:\\Users\\caiyo\\Desktop\\test.png")); //生成二维码图片
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static void main(String[] args) {
generateQRImage("test", "PNG", null, 151, 151);
}
/** /**
* @param matrix 二维码矩阵相关 * @param matrix 二维码矩阵相关
* @param format 二维码图片格式 * @param format 二维码图片格式
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment