1.maven 引入如下
2.代码
import java.io.File;
import java.util.Hashtable;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.pay.business.util.QRCodeUtilByZXing;
public class BuildQRcode {
public static void main(String[] args) {
String content = "https://www.oschina.net/";
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
Hashtable hints = new Hashtable();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
File file1 = new File("c:/", "扫我一下" + ".jpg");
try {
BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 350, 350, hints);
QRCodeUtilByZXing zx = new QRCodeUtilByZXing();
zx.writeToFile(bitMatrix, "jpg", file1);
} catch (Exception e) {
e.printStackTrace();
}finally{
}
}
}