androidandroid-canvasdrawpaint

Uneven line width in drawn stroke rectangle


I need to draw stroke rectangle with rounded corners. here is my code:

mLinePaint = new Paint();
mLinePaint.setColor(mDotColorTouched);
mLinePaint.setAntiAlias(true);
mLinePaint.setStrokeWidth(mLineWidth);
mLinePaint.setStyle(Paint.Style.STROKE);
mLinePaint.setStrokeCap(Paint.Cap.ROUND);

    bitmap = Bitmap.createBitmap(300, 
300, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bitmap);
    RectF r = new RectF(0, 0, 300 , 300);
    c.drawRoundRect(r, 30, 30, mLinePaint);

but as you can see the line width is bigger in the corners... any idea why it happens and how to fix this?

here is screen enter image description here


Solution

  • Try this set of code it's working.

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(10);
    
        Bitmap b = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(b);
        RectF rectF = new RectF();
        rectF.set(5,5,250,250);
        c.drawRoundRect(rectF, 10, 10, paint);
    
        imgView.setImageBitmap(b);
    

    enter image description here