String content = "www.baidu.com";
// 需要try catch
BitMatrix byteMatrix = new MultiFormatWriter().encode(new String(content.getBytes(), "iso-8859-1"),
BarcodeFormat.QR_CODE, 175, 175); //宽 高
int width = byteMatrix.getWidth();
int height = byteMatrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
// 设置颜色
image.setRGB(x, y, byteMatrix.get(x, y) ? BLACK : WHITE);
}
}
java 网址/字符串 转二维码
最新推荐文章于 2024-02-24 17:58:10 发布