有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

我一直在尝试使用java从json数据生成QRcode图像,但无法对QRcode图像中的值进行编码

  • 无法逐行读取JSON类型的数据
  • 无法使用以下命令将JSON对象中的值编码为图像 方法
public static void generate_qr(String name, String data) {
    try {
        String filePath = "W:\\FileDemo\\"+name+".png";
        String charset = "UTF-8"; // or "ISO-8859-1"
        Map < EncodeHintType, ErrorCorrectionLevel > hintMap = new HashMap <  > ();
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        BitMatrix matrix = new MultiFormatWriter().encode(
            new String(/*qrObj.getString("projectkey")*/data.toString().getBytes(charset), charset),
            BarcodeFormat.QR_CODE, 200, 200, hintMap);
        MatrixToImageWriter.writeToFile(matrix, filePath.substring(filePath
            .lastIndexOf(',') + 1), new File(filePath));
        System.out.println("QR Code image created successfully!");
    } catch (WriterException | IOException e) {
        System.err.println(e);
    }
}

共 (0) 个答案