慕村0971399
2019-01-28 20:13
为什么我的读出来的只有result
package com.imooc_qrcore;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import java.io.IOException;
import jp.sourceforge.qrcode.QRCodeDecoder;
public class ReadQRCode {
public static void main(String[] args) throws Exception {
File file =new File("D:/code/qrcode1.png");
BufferedImage bufferedImage=ImageIO.read(file);
QRCodeDecoder codeDecoder =new QRCodeDecoder();
String result= new String (codeDecoder.decode(new MYQRCodeImage(bufferedImage)),"gb2312");
System.out.println("result");
}
}
package com.imooc_qrcore;
import java.awt.image.BufferedImage;
import jp.sourceforge.qrcode.data.QRCodeImage;
public class MYQRCodeImage implements QRCodeImage {
BufferedImage bufferedImage;
public MYQRCodeImage(BufferedImage bufferedImage) {
this.bufferedImage=bufferedImage;
}
@Override
public int getHeight() {
// TODO Auto-generated method stub
return bufferedImage.getHeight();
}
@Override
public int getPixel(int arg0, int arg1) {
// TODO Auto-generated method stub
return bufferedImage.getRGB(arg0, arg1);
}
@Override
public int getWidth() {
// TODO Auto-generated method stub
return bufferedImage.getWidth();
}
}
package com.imooc_qrcore;
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 CreateQRCore {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
Qrcode x=new Qrcode();//jar 包里面的黑核心类
x.setQrcodeErrorCorrect('M');//纠错等级
x.setQrcodeEncodeMode('B');//N代表的是数字,A代表a-z,B代表其他字符
x.setQrcodeVersion(7);//版本,1-40
String qrData="www.imooc.com";
int width =67+12*(7-1);
int height =67+12*(7-1);
//创建一个缓冲区的图片
BufferedImage bufferedImage =new BufferedImage(67+12*(7-1),67+12*(7-1),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 =x.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("D:/code/qrcode1.png"));
}
}
System.out.println("result");就是一个字符串是不变的,result是一个变量 宝贝长点心吧
Java生成二维码
84511 学习 · 204 问题
相似问题