【问题标题】:How can I draw a QR code with rounded rectangles in android using java?如何使用java在android中绘制带有圆角矩形的QR码?
【发布时间】:2020-04-11 05:32:41
【问题描述】:

我一直致力于生成二维码并将其显示在屏幕上。现在我可以使用 Zxing 库来生成它,它给了我一个 BitMatrix,它返回一个关于 x 和 y 值的布尔值,如果该坐标需要是黑色或白色。现在我可以使用下面的代码成功生成并显示二维码了:

String charset = "UTF-8";
Map<EncodeHintType, ErrorCorrectionLevel> hintMap = new HashMap<>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);

BitMatrix matrix = new QRCodeWriter().encode(new String(url.getBytes(charset), charset), BarcodeFormat.QR_CODE, (int) context.getResources().getDimension(R.dimen.qr_square), (int) context.getResources().getDimension(R.dimen.qr_square), hintMap);


 Bitmap bitmap = Bitmap.createBitmap(matrix.getWidth(), matrix.getHeight(), Config.ARGB_8888);

 Canvas canvas = new Canvas(bitmap);
 Paint paint = new Paint();
 paint.setColor(Color.BLACK);
 for (int y = 0; y < matrix.getHeight(); y++) {
    for (int x = 0; x < matrix.getWidth(); x++) {
        if (!overlayRect.contains(x, y))
            canvas.drawPoint(x, y, paint);
    }
 }
 qrImageView.setImageBitmap(bitmap);

但现在设计师希望整个二维码都有圆角。我尝试了一些方法,但未能成功生成圆角二维码。任何帮助将不胜感激。 TIA

【问题讨论】:

    标签: java android canvas qr-code rounded-corners


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-02
      • 1970-01-01
      • 2013-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-11
      • 2010-11-18
      相关资源
      最近更新 更多