mirror of
https://github.com/zxing/zxing.git
synced 2025-02-20 18:47:38 -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;
|
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.MultiFormatWriter;
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
|
|
||||||
|
import com.beust.jcommander.JCommander;
|
||||||
|
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command line utility for encoding barcodes.
|
* Command line utility for encoding barcodes.
|
||||||
|
@ -46,10 +50,15 @@ public final class CommandLineEncoder {
|
||||||
if (EncoderConfig.DEFAULT_OUTPUT_FILE_BASE.equals(outFileString)) {
|
if (EncoderConfig.DEFAULT_OUTPUT_FILE_BASE.equals(outFileString)) {
|
||||||
outFileString += '.' + config.imageFormat.toLowerCase(Locale.ENGLISH);
|
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(
|
BitMatrix matrix = new MultiFormatWriter().encode(
|
||||||
config.contents.get(0), config.barcodeFormat, config.width, config.height);
|
config.contents.get(0), config.barcodeFormat, config.width,
|
||||||
MatrixToImageWriter.writeToPath(matrix, config.imageFormat, Paths.get(outFileString));
|
config.height, hints);
|
||||||
|
MatrixToImageWriter.writeToPath(matrix, config.imageFormat,
|
||||||
|
Paths.get(outFileString));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,11 +31,11 @@ final class EncoderConfig {
|
||||||
BarcodeFormat barcodeFormat = BarcodeFormat.QR_CODE;
|
BarcodeFormat barcodeFormat = BarcodeFormat.QR_CODE;
|
||||||
|
|
||||||
@Parameter(names = "--image_format",
|
@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";
|
String imageFormat = "PNG";
|
||||||
|
|
||||||
@Parameter(names = "--output",
|
@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;
|
String outputFileBase = DEFAULT_OUTPUT_FILE_BASE;
|
||||||
|
|
||||||
@Parameter(names = "--width",
|
@Parameter(names = "--width",
|
||||||
|
@ -48,6 +48,10 @@ final class EncoderConfig {
|
||||||
validateWith = PositiveInteger.class)
|
validateWith = PositiveInteger.class)
|
||||||
int height = 300;
|
int height = 300;
|
||||||
|
|
||||||
|
@Parameter(names = "--error_correction_level",
|
||||||
|
description = "Error correction level for the encoding")
|
||||||
|
String errorCorrectionLevel = null;
|
||||||
|
|
||||||
@Parameter(names = "--help",
|
@Parameter(names = "--help",
|
||||||
description = "Prints this help message",
|
description = "Prints this help message",
|
||||||
help = true)
|
help = true)
|
||||||
|
|
Loading…
Reference in a new issue