-
- public static void QrcodeImg(String context,String imgPath){
-
- Qrcode qrcode = new Qrcode();
-
-
- qrcode.setQrcodeErrorCorrect('M');
-
-
- qrcode.setQrcodeVersion(7);
-
-
- qrcode.setQrcodeEncodeMode('B');
-
-
- int width = 140;
- int height = 140;
- BufferedImage bufferImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
-
-
- Graphics2D gs = bufferImage.createGraphics();
-
-
- gs.setBackground(Color.white);
-
-
- gs.setColor(Color.black);
-
-
- gs.clearRect(0, 0, width, height);
-
- try {
- byte[] contentBytes = context.getBytes("utf-8");
- boolean[][] codeOut = qrcode.calQrcode(contentBytes);
- for(int i=0;i<codeOut.length;i++){
- for(int j=0;j<codeOut.length;j++){
- if(codeOut[j][i]){
-
- gs.fillRect(j*3+2, i*3+2, 3, 3);
- }
- }
- }
- gs.dispose();
-
- File imgFile = new File(imgPath);
- try {
- ImageIO.write(bufferImage, "png", imgFile);
- System.out.println("二维码生成成功!!!");
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- }
-
- public static void main(String[] args) {
- QrcodeImg("二维码中的内容", "c:/myclass/lan.png");
- }
posted @
2017-09-26 17:04
番茄爱上西红柿
阅读(
658)
评论()
收藏
举报