mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Merge pull request #476 from loikki/master
Add possibility to choose the error correction level for the encoding
This commit is contained in:
commit
2e5e2ea898
|
@ -16,12 +16,16 @@
|
|||
|
||||
package com.google.zxing.client.j2se;
|
||||
|
||||
import com.beust.jcommander.JCommander;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.MultiFormatWriter;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import com.beust.jcommander.JCommander;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Command line utility for encoding barcodes.
|
||||
|
@ -46,10 +50,15 @@ public final class CommandLineEncoder {
|
|||
if (EncoderConfig.DEFAULT_OUTPUT_FILE_BASE.equals(outFileString)) {
|
||||
outFileString += '.' + config.imageFormat.toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
Map<EncodeHintType, Object> hints = new HashMap<>();
|
||||
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);
|
||||
MatrixToImageWriter.writeToPath(matrix, config.imageFormat, Paths.get(outFileString));
|
||||
config.contents.get(0), config.barcodeFormat, config.width,
|
||||
config.height, hints);
|
||||
MatrixToImageWriter.writeToPath(matrix, config.imageFormat,
|
||||
Paths.get(outFileString));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,11 +31,11 @@ final class EncoderConfig {
|
|||
BarcodeFormat barcodeFormat = BarcodeFormat.QR_CODE;
|
||||
|
||||
@Parameter(names = "--image_format",
|
||||
description = "image output format, such as PNG, JPG, GIF")
|
||||
description = "Image output format, such as PNG, JPG, GIF")
|
||||
String imageFormat = "PNG";
|
||||
|
||||
@Parameter(names = "--output",
|
||||
description = " File to write to. Defaults to out.png")
|
||||
description = "File to write to. Defaults to out.png")
|
||||
String outputFileBase = DEFAULT_OUTPUT_FILE_BASE;
|
||||
|
||||
@Parameter(names = "--width",
|
||||
|
@ -48,6 +48,10 @@ final class EncoderConfig {
|
|||
validateWith = PositiveInteger.class)
|
||||
int height = 300;
|
||||
|
||||
@Parameter(names = "--error_correction_level",
|
||||
description = "Error correction level for the encoding")
|
||||
String errorCorrectionLevel = null;
|
||||
|
||||
@Parameter(names = "--help",
|
||||
description = "Prints this help message",
|
||||
help = true)
|
||||
|
|
Loading…
Reference in a new issue