use of com.google.zxing.qrcode.decoder.ErrorCorrectionLevel in project zxing by zxing.
the class ChartServlet method doParseParameters.
private static ChartServletRequestParameters doParseParameters(ServletRequest request, boolean readBody) throws IOException {
Preconditions.checkArgument("qr".equals(request.getParameter("cht")), "Bad type");
String widthXHeight = request.getParameter("chs");
Preconditions.checkNotNull(widthXHeight, "No size");
int xIndex = widthXHeight.indexOf('x');
Preconditions.checkArgument(xIndex >= 0, "Bad size");
int width = Integer.parseInt(widthXHeight.substring(0, xIndex));
int height = Integer.parseInt(widthXHeight.substring(xIndex + 1));
Preconditions.checkArgument(width > 0 && height > 0, "Bad size");
Preconditions.checkArgument(width <= MAX_DIMENSION && height <= MAX_DIMENSION, "Bad size");
String outputEncodingName = request.getParameter("choe");
Charset outputEncoding = StandardCharsets.UTF_8;
if (outputEncodingName != null) {
outputEncoding = Charset.forName(outputEncodingName);
Preconditions.checkArgument(SUPPORTED_OUTPUT_ENCODINGS.contains(outputEncoding), "Bad output encoding");
}
ErrorCorrectionLevel ecLevel = ErrorCorrectionLevel.L;
int margin = 4;
String ldString = request.getParameter("chld");
if (ldString != null) {
int pipeIndex = ldString.indexOf('|');
if (pipeIndex < 0) {
// Only an EC level
ecLevel = ErrorCorrectionLevel.valueOf(ldString);
} else {
ecLevel = ErrorCorrectionLevel.valueOf(ldString.substring(0, pipeIndex));
margin = Integer.parseInt(ldString.substring(pipeIndex + 1));
Preconditions.checkArgument(margin > 0, "Bad margin");
}
}
String text;
if (readBody) {
text = CharStreams.toString(request.getReader());
} else {
text = request.getParameter("chl");
}
Preconditions.checkArgument(text != null && !text.isEmpty(), "No input");
return new ChartServletRequestParameters(width, height, outputEncoding, ecLevel, margin, text);
}
use of com.google.zxing.qrcode.decoder.ErrorCorrectionLevel in project zxing by zxing.
the class QRCodeWriter method encode.
@Override
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType, ?> hints) throws WriterException {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' + height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = QUIET_ZONE_SIZE;
if (hints != null) {
if (hints.containsKey(EncodeHintType.ERROR_CORRECTION)) {
errorCorrectionLevel = ErrorCorrectionLevel.valueOf(hints.get(EncodeHintType.ERROR_CORRECTION).toString());
}
if (hints.containsKey(EncodeHintType.MARGIN)) {
quietZone = Integer.parseInt(hints.get(EncodeHintType.MARGIN).toString());
}
}
QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
return renderResult(code, width, height, quietZone);
}
use of com.google.zxing.qrcode.decoder.ErrorCorrectionLevel in project weex-example by KalicyZhou.
the class QRCodeWriter method encode.
@Override
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType, ?> hints) throws WriterException {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' + height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = QUIET_ZONE_SIZE;
if (hints != null) {
if (hints.containsKey(EncodeHintType.ERROR_CORRECTION)) {
errorCorrectionLevel = ErrorCorrectionLevel.valueOf(hints.get(EncodeHintType.ERROR_CORRECTION).toString());
}
if (hints.containsKey(EncodeHintType.MARGIN)) {
quietZone = Integer.parseInt(hints.get(EncodeHintType.MARGIN).toString());
}
}
QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
return renderResult(code, width, height, quietZone);
}
use of com.google.zxing.qrcode.decoder.ErrorCorrectionLevel in project collect by opendatakit.
the class QRCodeUtils method encode.
public Bitmap encode(String data) throws IOException, WriterException {
String compressedData = CompressionUtils.compress(data);
// Maximum capacity for QR Codes is 4,296 characters (Alphanumeric)
if (compressedData.length() > 4000) {
throw new IOException(getLocalizedString(Collect.getInstance(), R.string.encoding_max_limit));
}
Map<EncodeHintType, ErrorCorrectionLevel> hints = new HashMap<>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix bitMatrix = qrCodeWriter.encode(compressedData, BarcodeFormat.QR_CODE, QR_CODE_SIDE_LENGTH, QR_CODE_SIDE_LENGTH, hints);
Bitmap bmp = Bitmap.createBitmap(QR_CODE_SIDE_LENGTH, QR_CODE_SIDE_LENGTH, Bitmap.Config.RGB_565);
for (int x = 0; x < QR_CODE_SIDE_LENGTH; x++) {
for (int y = 0; y < QR_CODE_SIDE_LENGTH; y++) {
bmp.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
}
}
return bmp;
}
use of com.google.zxing.qrcode.decoder.ErrorCorrectionLevel in project incubator-weex by apache.
the class QRCodeWriter method encode.
@Override
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType, ?> hints) throws WriterException {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' + height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = QUIET_ZONE_SIZE;
if (hints != null) {
if (hints.containsKey(EncodeHintType.ERROR_CORRECTION)) {
errorCorrectionLevel = ErrorCorrectionLevel.valueOf(hints.get(EncodeHintType.ERROR_CORRECTION).toString());
}
if (hints.containsKey(EncodeHintType.MARGIN)) {
quietZone = Integer.parseInt(hints.get(EncodeHintType.MARGIN).toString());
}
}
QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
return renderResult(code, width, height, quietZone);
}
Aggregations