文件名称:java实现二维码生成
文件大小:1KB
文件格式:JAVA
更新时间:2016-09-26 12:19:48
二维码生成
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import com.swetake.util.Qrcode;
public class QRCodeEncoderTest {
public static void main(String[] args) throws Exception {
Qrcode qrcode=new Qrcode();
qrcode.setQrcodeErrorCorrect('M');
qrcode.setQrcodeEncodeMode('B');
qrcode.setQrcodeVersion(7);
String testString = "_-+^%$#@!~`=&)*(";
byte[] d =testString.getBytes("GBK");
BufferedImage bi = new BufferedImage(139, 139, BufferedImage.TYPE_INT_RGB);
// createGraphics
Graphics2D g = bi.createGraphics();
// set background
g.setBackground(Color.WHITE);
g.clearRect(0, 0, 139, 139);
g.setColor(Color.BLACK);
if (d.length>0 && d.length <123){
boolean[][] b = qrcode.calQrcode(d);
for (int i=0;i