类com.google.zxing.Writer源码实例Demo

下面列出了怎么用com.google.zxing.Writer的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: oath   文件: QRCodeWriter.java
private void doWrite(OutputStream os, Path path) throws IOException {
    try {
        Writer writer = new MultiFormatWriter();
        Map<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
        hints.put(EncodeHintType.CHARACTER_SET, StandardCharsets.UTF_8.name());
        hints.put(EncodeHintType.MARGIN, Integer.valueOf(margin));
        hints.put(EncodeHintType.ERROR_CORRECTION, com.google.zxing.qrcode.decoder.ErrorCorrectionLevel.forBits(errorCorrectionLevel.getBits()));
        BitMatrix matrix = writer.encode(uri.toUriString(), BarcodeFormat.QR_CODE, width, height, hints);
        if (os != null) {
            MatrixToImageWriter.writeToStream(matrix, imageFormatName, os);
        }
        else {
            MatrixToImageWriter.writeToPath(matrix, imageFormatName, path);
        }
    } catch (WriterException e) {
        throw new IOException(e);
    }
}
 
源代码2 项目: java-totp   文件: ZxingPngQrGeneratorTest.java
@Test
public void testExceptionIsWrapped() throws WriterException {
    Throwable exception = new RuntimeException();
    Writer writer = mock(Writer.class);
    when(writer.encode(anyString(), any(), anyInt(), anyInt())).thenThrow(exception);

    ZxingPngQrGenerator generator = new ZxingPngQrGenerator(writer);

    QrGenerationException e = assertThrows(QrGenerationException.class, () -> {
        generator.generate(getData());
    });

    assertEquals("Failed to generate QR code. See nested exception.", e.getMessage());
    assertEquals(exception, e.getCause());
}
 
源代码3 项目: java-totp   文件: ZxingPngQrGenerator.java
public ZxingPngQrGenerator(Writer writer) {
    this.writer = writer;
}
 
 类所在包
 类方法
 同包方法