0

How to draw four boundary rounded corner in canvas for journeyapps zxing qr code scanner Java code? Here is the code that I used. Just a rectangle with no rounding. How to create a rounded rectangle with custom radius.

Please see imag

1

This is my java code, but the corners are square instead of round.

// Length rate of line and frame
private float mLineRate = 0.1f;

// Line depth
private float mLineDepth =
        TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics());

// Line color
private int mLineColor = Color.rgb(244, 165, 37);

    @Override
    public void onDraw (Canvas canvas){
        refreshSizes();
        if (framingRect == null || previewSize == null) {
            return;
        }

        final Rect frame = framingRect;
        final Size previewSize = this.previewSize;

        final int width = getWidth();
        final int height = getHeight();

// [Custom start] Draw 4 corner lines
    paint.setColor(mLineColor);
    canvas.drawRect(frame.left, frame.top,frame.left + frame.width() * mLineRate,frame.top + mLineDepth, paint);
    canvas.drawRect(frame.left, frame.top, frame.left + mLineDepth, frame.top + frame.height() * mLineRate, paint);

    canvas.drawRect(frame.right - frame.width() * mLineRate, frame.top, frame.right, frame.top + mLineDepth, paint);
    canvas.drawRect(frame.right - mLineDepth, frame.top, frame.right, frame.top + frame.height() * mLineRate, paint);

    canvas.drawRect(frame.left,frame.bottom - mLineDepth,frame.left + frame.width() * mLineRate, frame.bottom, paint);
    canvas.drawRect(frame.left, frame.bottom - frame.height() * mLineRate, frame.left + mLineDepth, frame.bottom, paint);

    canvas.drawRect(frame.right - frame.width() * mLineRate, frame.bottom - mLineDepth, frame.right, frame.bottom, paint);
    canvas.drawRect(frame.right - mLineDepth, frame.bottom - frame.height() * mLineRate, frame.right, frame.bottom, paint);
    // [Custom end]

Please help me.

vimuth
  • 5,064
  • 33
  • 79
  • 116
Developer
  • 1
  • 2

1 Answers1

0

Skip this and use lottiefiles on viewfinder. This is very hatic.

  • Please try and answer the question itself rather than suggesting a completely different technology. Thanks! – boylec1986 Jun 07 '23 at 16:42