com.google.zxing.qrcode.encoder.Encoder Java Examples

The following examples show how to use com.google.zxing.qrcode.encoder.Encoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UI.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
public static Bitmap getQRCode(final String data) {
    final ByteMatrix matrix;
    try {
        matrix = Encoder.encode(data, ErrorCorrectionLevel.M).getMatrix();
    } catch (final WriterException e) {
        throw new RuntimeException(e);
    }

    final int height = matrix.getHeight() * SCALE;
    final int width = matrix.getWidth() * SCALE;
    final int min = height < width ? height : width;

    final Bitmap mQRCode = Bitmap.createBitmap(min, min, Bitmap.Config.ARGB_8888);
    for (int x = 0; x < min; ++x)
        for (int y = 0; y < min; ++y)
            mQRCode.setPixel(x, y, matrix.get(x / SCALE, y / SCALE) == 1 ? Color.BLACK : Color.TRANSPARENT);
    return mQRCode;
}
 
Example #2
Source File: QRCodeWriter.java    From letv with Apache License 2.0 6 votes vote down vote up
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType, ?> hints) throws WriterException {
    if (contents.length() == 0) {
        throw new IllegalArgumentException("Found empty contents");
    } else if (format != BarcodeFormat.QR_CODE) {
        throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
    } else if (width < 0 || height < 0) {
        throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' + height);
    } else {
        ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
        int quietZone = 4;
        if (hints != null) {
            ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
            if (requestedECLevel != null) {
                errorCorrectionLevel = requestedECLevel;
            }
            Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
            if (quietZoneInt != null) {
                quietZone = quietZoneInt.intValue();
            }
        }
        return renderResult(Encoder.encode(contents, errorCorrectionLevel, hints), width, height, quietZone);
    }
}
 
Example #3
Source File: QrBitmap.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
public Bitmap getQRCode() {
    if (mQRCode == null) {
        final ByteMatrix matrix;
        try {
            matrix = Encoder.encode(mData, ErrorCorrectionLevel.M).getMatrix();
        } catch (final WriterException e) {
            throw new RuntimeException(e);
        }
        final int height = matrix.getHeight() * SCALE;
        final int width = matrix.getWidth() * SCALE;
        mQRCode = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        for (int x = 0; x < width; ++x)
            for (int y = 0; y < height; ++y)
                mQRCode.setPixel(x, y, matrix.get(x / SCALE, y / SCALE) == 1 ? Color.BLACK : mBackgroundColor);
    }
    return mQRCode;
}
 
Example #4
Source File: GenerateQRInteractor.java    From iroha-android with Apache License 2.0 6 votes vote down vote up
@Override
protected Single<Bitmap> build(String amount) {
    return Single.create(emitter -> {
        String username = preferenceUtils.retrieveUsername();
        String qrText = username + "," + amount;
                    Map<EncodeHintType, String> hints = new HashMap<>();
        hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        QRCode qrCode = Encoder.encode(qrText, ErrorCorrectionLevel.H, hints);
        final ByteMatrix byteMatrix = qrCode.getMatrix();
        final int width = byteMatrix.getWidth();
        final int height = byteMatrix.getHeight();
        final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                byte val = byteMatrix.get(x, y);
                bitmap.setPixel(x, y, val == 1 ? Color.BLACK : Color.WHITE);
            }
        }
        emitter.onSuccess(Bitmap.createScaledBitmap(bitmap, SIZE, SIZE, false));
    });
}
 
Example #5
Source File: QRCodeWriter.java    From QrCodeScanner with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #6
Source File: SendCodeGenerator.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
/**
 * This object renders a QR Code as a ByteMatrix 2D array of greyscale
 * values.
 * 
 * @author [email protected] (Daniel Switkin)
 */
public ByteMatrix encode(String contents) throws WriterException {

	if (contents == null || contents.length() == 0) {
		throw new IllegalArgumentException("Found empty contents");
	}

	Encoder.encode(contents, ErrorCorrectionLevel.L);
	return renderResult(code, QR_CODE_ELEMENT_MULTIPLE);
}
 
Example #7
Source File: QRCodeWriter.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
@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) {
		ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
		if (requestedECLevel != null) {
			errorCorrectionLevel = requestedECLevel;
		}
		Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
		if (quietZoneInt != null) {
			quietZone = quietZoneInt;
		}
	}

	QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
	return renderResult(code, width, height, quietZone);
}
 
Example #8
Source File: QRCodeWriter.java    From reacteu-app with MIT License 5 votes vote down vote up
@Override
public BitMatrix encode(String contents,
                        BarcodeFormat format,
                        int width,
                        int height,
                        Map<EncodeHintType,?> hints) throws WriterException {

  if (contents.length() == 0) {
    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) {
    ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
    if (requestedECLevel != null) {
      errorCorrectionLevel = requestedECLevel;
    }
    Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
    if (quietZoneInt != null) {
      quietZone = quietZoneInt;
    }
  }

  QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
  return renderResult(code, width, height, quietZone);
}
 
Example #9
Source File: QRCodeWriter.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
@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);
}
 
Example #10
Source File: QRCodeWriter.java    From weex with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #11
Source File: QRCodeWriter.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #12
Source File: QRCodeWriter.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
@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) {
    ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
    if (requestedECLevel != null) {
      errorCorrectionLevel = requestedECLevel;
    }
    Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
    if (quietZoneInt != null) {
      quietZone = quietZoneInt;
    }
  }

  QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
  return renderResult(code, width, height, quietZone);
}
 
Example #13
Source File: QRCodeWriter.java    From Tesseract-OCR-Scanner with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: QRCodeWriter.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
public BitMatrix encode(String contents, int width, int height, Map<EncodeHintType, ?> hints)
        throws WriterException {

    if (contents.isEmpty()) {
        throw new IllegalArgumentException("Found empty contents");
    }

    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) {
        ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
        if (requestedECLevel != null) {
            errorCorrectionLevel = requestedECLevel;
        }
        Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
        if (quietZoneInt != null) {
            quietZone = quietZoneInt;
        }
    }

    QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
    return renderResult(code, width, height, quietZone);
}
 
Example #15
Source File: QRCodeWriter.java    From ScreenCapture with MIT License 5 votes vote down vote up
@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);
}
 
Example #16
Source File: QrBitmap.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public Bitmap getQRCode() throws Exception {
    if (mQRCode == null) {
        final ByteMatrix matrix;
        matrix = Encoder.encode(mData, ErrorCorrectionLevel.M).getMatrix();
        final int height = matrix.getHeight() * SCALE;
        final int width = matrix.getWidth() * SCALE;
        mQRCode = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        for (int x = 0; x < width; ++x)
            for (int y = 0; y < height; ++y)
                mQRCode.setPixel(x, y, matrix.get(x / SCALE, y / SCALE) == 1 ? Color.BLACK : mBackgroundColor);
    }
    return mQRCode;
}
 
Example #17
Source File: QRCodeWriter.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@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());
        }
    }

    code = Encoder.encode(contents, errorCorrectionLevel, hints);
    return renderResult(width, height, quietZone);
}
 
Example #18
Source File: DouYuBroadcastService.java    From Alice-LiveMan with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public InputStream getBroadcastCaptcha() throws IOException {
    Map<String, String> requestProperties = new HashMap<>();
    requestProperties.put("referer", "https://passport.douyu.com/index/login?passport_reg_callback=PASSPORT_REG_SUCCESS_CALLBACK&passport_login_callback=PASSPORT_LOGIN_SUCCESS_CALLBACK&passport_close_callback=PASSPORT_CLOSE_CALLBACK&passport_dp_callback=PASSPORT_DP_CALLBACK&type=login&client_id=1&state=https%3A%2F%2Fwww.douyu.com%2F&source=click_topnavi_login");
    requestProperties.put("x-requested-with", "XMLHttpRequest");
    String generateCodeJSON = HttpRequestUtil.downloadUrl(URI.create(URL_GENERATE_CODE), null, "client_id=1", requestProperties, StandardCharsets.UTF_8);
    JSONObject generateCode = JSON.parseObject(generateCodeJSON);
    if (generateCode.getInteger("error") == 0) {
        String url = generateCode.getJSONObject("data").getString("url");
        String code = generateCode.getJSONObject("data").getString("code");
        session.setAttribute(SESSION_ATTRIBUTE, code);
        try {
            QRCode qrCode = Encoder.encode(url, ErrorCorrectionLevel.M);
            BufferedImage qrCodeImage = new BufferedImage(qrCode.getMatrix().getWidth(), qrCode.getMatrix().getHeight(), BufferedImage.TYPE_BYTE_BINARY);
            for (int x = 0; x < qrCodeImage.getWidth(); x++) {
                for (int y = 0; y < qrCodeImage.getHeight(); y++) {
                    if (qrCode.getMatrix().get(x, y) == 0) {
                        qrCodeImage.setRGB(x, y, Color.WHITE.getRGB());
                    }
                }
            }
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ImageIO.write(qrCodeImage, "bmp", bos);
            return new ByteArrayInputStream(bos.toByteArray());
        } catch (WriterException e) {
            throw new IOException(e);
        }
    } else {
        log.error("获取qrcode失败:" + generateCodeJSON);
    }
    return null;
}
 
Example #19
Source File: PrinterCommands.java    From PrinterThermal-ESCPOS-Android with MIT License 4 votes vote down vote up
/**
 * Convert a string to QR Code byte array compatible with ESC/POS printer.
 *
 * @param data String data to convert in QR Code
 * @return Bytes contain the image in ESC/POS command
 */
public static byte[] QRCodeDataToBytes(String data, int size) {

    ByteMatrix byteMatrix = null;

    try {
        EnumMap<EncodeHintType, Object> hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");

        QRCode code = Encoder.encode(data, ErrorCorrectionLevel.L, hints);
        byteMatrix = code.getMatrix();

    } catch (WriterException e) {
        e.printStackTrace();
    }

    if (byteMatrix == null) {
        return PrinterCommands.initImageCommand(0, 0);
    }

    int
            width = byteMatrix.getWidth(),
            height = byteMatrix.getHeight(),
            coefficient = Math.round((float) size / (float) width),
            imageWidth = width * coefficient,
            imageHeight = height * coefficient,
            bytesByLine = (int) Math.ceil(((float) imageWidth) / 8f),
            i = 8;

    if (coefficient < 1) {
        return PrinterCommands.initImageCommand(0, 0);
    }

    byte[] imageBytes = PrinterCommands.initImageCommand(bytesByLine, imageHeight);

    for (int y = 0; y < height; y++) {
        byte[] lineBytes = new byte[bytesByLine];
        int j = 0, multipleX = coefficient;
        boolean isBlack = false;
        for (int x = -1; x < width;) {
            StringBuilder stringBinary = new StringBuilder();
            for (int k = 0; k < 8; k++) {
                if(multipleX == coefficient) {
                    isBlack = ++x < width && byteMatrix.get(x, y) == 1;
                    multipleX = 0;
                }
                stringBinary.append(isBlack ? "1" : "0");
                ++multipleX;
            }
            lineBytes[j++] = (byte) Integer.parseInt(stringBinary.toString(), 2);
        }

        for (int multipleY = 0; multipleY < coefficient; ++multipleY) {
            System.arraycopy(lineBytes, 0, imageBytes, i, lineBytes.length);
            i += lineBytes.length;
        }
    }

    return imageBytes;
}
 
Example #20
Source File: QRCodeGenerator.java    From bither-desktop-java with Apache License 2.0 3 votes vote down vote up
public static ByteMatrix encode(String contents) throws WriterException {

        if (contents == null || contents.length() == 0) {
            throw new IllegalArgumentException("Found empty contents");
        }

        QRCode code = Encoder.encode(contents, ErrorCorrectionLevel.L);

        return renderResult(code, QR_CODE_ELEMENT_MULTIPLE);
    }
 
Example #21
Source File: QRCodeGenerator.java    From bither-desktop-java with Apache License 2.0 3 votes vote down vote up
public static ByteMatrix encode(String contents) throws WriterException {

        if (contents == null || contents.length() == 0) {
            throw new IllegalArgumentException("Found empty contents");
        }

        QRCode code = Encoder.encode(contents, ErrorCorrectionLevel.L);

        return renderResult(code, QR_CODE_ELEMENT_MULTIPLE);
    }