Пример #1
0
 /**
  * Returns a {@link android.graphics.Bitmap} without creating a {@link java.io.File} first.
  *
  * @return {@link android.graphics.Bitmap} of this QRCode
  */
 public Bitmap bitmap() {
   try {
     return MatrixToImageWriter.toBitmap(createMatrix(text));
   } catch (WriterException e) {
     throw new RuntimeException(
         "Failed to create QR image from text due to underlying exception", e);
   }
 }
Пример #2
0
  public static void main(String[] args) throws Exception {
    EncoderConfig config = new EncoderConfig();
    JCommander jCommander = new JCommander(config, args);
    jCommander.setProgramName(CommandLineEncoder.class.getSimpleName());
    if (config.help) {
      jCommander.usage();
      return;
    }

    String outFileString = config.outputFileBase;
    if (EncoderConfig.DEFAULT_OUTPUT_FILE_BASE.equals(outFileString)) {
      outFileString += '.' + config.imageFormat.toLowerCase(Locale.ENGLISH);
    }
    Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
    if (config.errorCorrectionLevel != null) {
      hints.put(EncodeHintType.ERROR_CORRECTION, config.errorCorrectionLevel);
    }
    BitMatrix matrix =
        new MultiFormatWriter()
            .encode(
                config.contents.get(0), config.barcodeFormat, config.width, config.height, hints);
    MatrixToImageWriter.writeToPath(matrix, config.imageFormat, Paths.get(outFileString));
  }