zoukankan      html  css  js  c++  java
  • 二维码QRCode

    package com.aig.ecompass.ecard;
    
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;
    
    import javax.imageio.ImageIO;
    
    import com.google.zxing.BarcodeFormat;
    import com.google.zxing.EncodeHintType;
    import com.google.zxing.MultiFormatWriter;
    import com.google.zxing.common.BitMatrix;
    
     
    
    public class EcardQRCode {
    private static final int BLACK = 0xFF000000;
    private static final int WHITE = 0xFFFFFFFF;
    public static void createQRCode(){
    //WebSphere Application Server v8.0 at localhost
    String content = "AIA Technology Shared Service,ECard QRCode";
    String path = "D:/";
    String suffix="png";
    
    
    try {
    MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
    
    Map hints = new HashMap();
    hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
    BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 400, 400,hints);
    File file = new File(path,"ecard.png");
    
    int width = bitMatrix.getWidth();
    int height = bitMatrix.getHeight();
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    for (int x = 0; x < width; x++) {
    for (int y = 0; y < height; y++) {
    image.setRGB(x, y, bitMatrix.get(x, y) ? BLACK : WHITE);
    }
    }
    if (!ImageIO.write(image, suffix, file)) {
    throw new IOException("Could not write an image of format " + suffix + " to " + file);
    }
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    
    public static void main(String[] args) {
    createQRCode();
    }
    
    
    }

    使用zxing的core.jar包,zxing为Google开源包。生成二维码。

  • 相关阅读:
    我罗斯方块最终篇
    我罗斯汇报作业一
    11组-Alpha冲刺-2/6
    11组-Alpha冲刺-1/6
    结对编程作业
    11组 团队展示
    第一次个人编程作业
    第一次博客作业
    寒假作业3
    寒假作业2
  • 原文地址:https://www.cnblogs.com/jingRegina/p/5500601.html
Copyright © 2011-2022 走看看