QRcode的字符串处理大小问题
我用的QRcode 生成二维码,汉字不能超过61个,我查资料汉字可以支持960左右
我的代码
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;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import jp.sourceforge.qrcode.QRCodeDecoder;
import jp.sourceforge.qrcode.data.QRCodeImage;
import jp.sourceforge.qrcode.exception.DecodingFailedException;
public class erWeiManage {
public void createErwei(String testString,String FilePath) 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<b.length;i++){
for (int j=0;j<b.length;j++){
if (b[j][i]) {
g.fillRect(j*3+2,i*3+2,3,3);
}
}
}
}
g.dispose();
bi.flush();
File f = new File(FilePath);
ImageIO.write(bi, "png", f);
System.out.println("doned!");
}