課程
/后端開發
/Java
/Java生成二維碼
byte[] d = qrData.getBytes("gd2312");
qrDate是錯的,識別不了
2018-01-27
源自:Java生成二維碼 6-4
正在回答
public?static?void?main(String[]?args)?throws?IOException?{ Qrcode?xQrcode?=?new?Qrcode(); xQrcode.setQrcodeEncodeMode('B');//N代表數字,A代表a-Z,B代表其他字符 xQrcode.setQrcodeErrorCorrect('M');//糾錯等級 xQrcode.setQrcodeVersion(7);//版本 String?qrData?=?"www.xianlaiwan.cn"; int?width?=?67?+?12?*?(?7?-?1?);//7是版本 int?height?=?67?+?12?*?(?7?-?1?); BufferedImage?bufferedImage?=?new?BufferedImage(width,?height,?BufferedImage.TYPE_INT_RGB); Graphics2D?gs?=?bufferedImage.createGraphics(); gs.setBackground(Color.white); gs.setColor(Color.BLACK); gs.clearRect(0,?0,?width,?height); int?pixoff?=?2;//偏移量 byte[]?d?=?qrData.getBytes("gb2312"); if(d.length>0?&&?d.length<120){ boolean[][]?s?=?xQrcode.calQrcode(d); for(int?i=0;i<s.length;i++){ for(int?j=0;j<s.length;j++){ if(s[j][i]){ gs.fillRect(j*3+pixoff,?i*3+pixoff,?3,?3); } } } } gs.dispose(); bufferedImage.flush(); ImageIO.write(bufferedImage,?"png",?new?File("c:/image2.png")); }
public static void main(String[] args) throws IOException {
Qrcode xQrcode = new Qrcode();
xQrcode.setQrcodeEncodeMode('B');//N代表數字,A代表a-Z,B代表其他字符
xQrcode.setQrcodeErrorCorrect('M');//糾錯等級
xQrcode.setQrcodeVersion(7);//版本
String qrData = "www.xianlaiwan.cn";
int width = 67 + 12 * ( 7 - 1 );//7是版本
int height = 67 + 12 * ( 7 - 1 );
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D gs = bufferedImage.createGraphics();
gs.setBackground(Color.white);
gs.setColor(Color.BLACK);
gs.clearRect(0, 0, width, height);
int pixoff = 2;//偏移量
byte[] d = qrData.getBytes("gb2312");
if(d.length>0 && d.length<120){
boolean[][] s = xQrcode.calQrcode(d);
for(int i=0;i<s.length;i++){
for(int j=0;j<s.length;j++){
if(s[j][i]){
gs.fillRect(j*3+pixoff, i*3+pixoff, 3, 3);
}
gs.dispose();
bufferedImage.flush();
ImageIO.write(bufferedImage, "png", new File("c:/image2.png"));
舉報
二維碼無處不在,自己動手用Java生成二維碼,三種生成方式任你選
1 回答qrcode
1 回答QRCODE解析時報錯
4 回答如何在maven項目配置qrcode
3 回答qrcode方式解析報異常
2 回答我用QRCode生成二維碼圖片用zxing decode出來是亂碼,并且 我用QRCode decode報錯
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-02-28
2018-02-28
public static void main(String[] args) throws IOException {
Qrcode xQrcode = new Qrcode();
xQrcode.setQrcodeEncodeMode('B');//N代表數字,A代表a-Z,B代表其他字符
xQrcode.setQrcodeErrorCorrect('M');//糾錯等級
xQrcode.setQrcodeVersion(7);//版本
String qrData = "www.xianlaiwan.cn";
int width = 67 + 12 * ( 7 - 1 );//7是版本
int height = 67 + 12 * ( 7 - 1 );
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D gs = bufferedImage.createGraphics();
gs.setBackground(Color.white);
gs.setColor(Color.BLACK);
gs.clearRect(0, 0, width, height);
int pixoff = 2;//偏移量
byte[] d = qrData.getBytes("gb2312");
if(d.length>0 && d.length<120){
boolean[][] s = xQrcode.calQrcode(d);
for(int i=0;i<s.length;i++){
for(int j=0;j<s.length;j++){
if(s[j][i]){
gs.fillRect(j*3+pixoff, i*3+pixoff, 3, 3);
}
}
}
}
gs.dispose();
bufferedImage.flush();
ImageIO.write(bufferedImage, "png", new File("c:/image2.png"));
}