1. 程式人生 > 其它 >java生成二維碼

java生成二維碼

技術標籤:java技術

/**
     * 生成二維碼
     *
     * @throws WriterException
     * @throws IOException
     */
    public static BufferedImage testEncode(int width,int height,String content) throws WriterException, IOException {
        String format = "jpg";// 影象型別
        Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
        hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
                BarcodeFormat.QR_CODE, width, height, hints);// 生成矩陣
        BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
        System.out.println("輸出成功.");
        return bufferedImage;
    }