java生成二维码,上传到oss

@Test
public void qrcode() throws Exception {
   QRCodeWriter qrCodeWriter = new QRCodeWriter();
   int width = 430, height = 430;
   BitMatrix bitMatrix = qrCodeWriter.encode("xxxxxxxxxx", BarcodeFormat.QR_CODE, width, height);

   ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
   MatrixToImageWriter.writeToStream(bitMatrix, "PNG", outputStream);

   ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());

   String png = OSSUtil.uploadImage(inputStream, ".png", width, height);
   System.out.println(png);

//        MatrixToImageWriter.writeToPath(bitMatrix, "PNG",
//                FileSystems.getDefault().getPath("d:\\test.png"));

}
compile group: 'com.google.zxing', name: 'core', version: '3.4.0'
compile group: 'com.google.zxing', name: 'javase', version: '3.4.0'

你可能感兴趣的:(java)