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开源包。生成二维码。

  • 相关阅读:
    卡特兰数
    Tree
    关于树上DP的转移方式与复杂度证明
    Tarjan进阶
    排队
    Perm 排列计数
    [bzoj1227]虔诚的墓主人
    [BZOJ1195]最短母串
    ValueError: Variable vgg_16/conv1/conv1_1/weights already exists, disallowed
    《链家网技术架构的演进之路》读后感
  • 原文地址:https://www.cnblogs.com/jingRegina/p/5500601.html
Copyright © 2011-2022 走看看