Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5970567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:23:38+00:00 2026-05-22T20:23:38+00:00

I need to round the corners of a Bitmap . After that, I need

  • 0

I need to round the corners of a Bitmap. After that, I need to add a border for it. I have done the source below to round the corners but I don’t know how to draw a border in the Bitmap using Canvas. Is there any way to do it? Thanks

Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(),
    Config.ARGB_8888);
Canvas canvas = new Canvas(output);
            
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
    
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawRoundRect(rectF, 20.0f, 20.0f, paint);
    
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
    
return output;

I have added the solution:

Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), 
    Config.ARGB_8888);
Canvas canvas = new Canvas(output);
            
Paint paint = new Paint();
Paint paintStroke = new Paint();
            
paintStroke.setStrokeWidth(2);
paintStroke.setStyle(Paint.Style.STROKE);
paintStroke.setColor(Color.RED);
paintStroke.setAntiAlias(true);
            
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
    
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
            
canvas.drawRoundRect(rectF, 20.0f, 20.0f, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
canvas.drawRoundRect(rectF, round, round, paintStroke);
    
return output;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:23:39+00:00Added an answer on May 22, 2026 at 8:23 pm

    try this Method and pass bitmap it will return bitmap with border with angle :

    Bitmap rotateAndFrame(Bitmap bitmap,float angle) {
        // final boolean positive = sRandom.nextFloat() >= 0.5f;
        // final float angle = (ROTATION_ANGLE_MIN + sRandom.nextFloat() * 
        //     ROTATION_ANGLE_EXTRA) * (positive ? 1.0f : -1.0f);
        final double radAngle = Math.toRadians(angle);
    
        final int bitmapWidth = bitmap.getWidth();
        final int bitmapHeight = bitmap.getHeight();
    
        final double cosAngle = Math.abs(Math.cos(radAngle));
        final double sinAngle = Math.abs(Math.sin(radAngle));
    
        final int strokedWidth = (int) (bitmapWidth + 2 * PHOTO_BORDER_WIDTH);
        final int strokedHeight = (int) (bitmapHeight + 2 * PHOTO_BORDER_WIDTH);
    
        final int width = (int) (strokedHeight * sinAngle + strokedWidth * cosAngle);
        final int height = (int) (strokedWidth * sinAngle + strokedHeight * cosAngle);
    
        final float x = (width - bitmapWidth) / 2.0f;
        final float y = (height - bitmapHeight) / 2.0f;
    
        final Bitmap decored = Bitmap.createBitmap(width, height, 
            Bitmap.Config.ARGB_8888);
           
        final Canvas canvas = new Canvas(decored);
    
        canvas.rotate(angle, width / 2.0f, height / 2.0f);
        canvas.drawBitmap(bitmap, x, y, sPaint);
        canvas.drawRect(x, y, x + bitmapWidth, y + bitmapHeight, sStrokePaint);
        canvas.drawText(String.valueOf(k_value),(one_piecewidth*0.84f),
            (one_pieceheight*0.35f),sNumPaint);
        k++;
        return decored;
    }
    

    hope it helps…

    edited:

    private static final float PHOTO_BORDER_WIDTH2 = 3.0f;
    private static final float PHOTO_BORDER_WIDTH = 1.0f;
    private static final int PHOTO_BORDER_COLOR2=0x00000000;
    private static final int PHOTO_BORDER_COLOR = 0xffffffff;
    
    private static final Paint sPaint = 
        new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    private static final Paint sStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private static final Paint sNumPaint = new Paint(Paint.LINEAR_TEXT_FLAG);
    static {
        sNumPaint.setColor(Color.BLACK);
        sNumPaint.setTextSize(25);
        sNumPaint.setTextAlign(Align.RIGHT);
    }
    static {
        sStrokePaint.setStrokeWidth(PHOTO_BORDER_WIDTH);
        sStrokePaint.setStyle(Paint.Style.STROKE);
        // sStrokePaint.measureText("hello");
        sStrokePaint.setColor(PHOTO_BORDER_COLOR);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add Round corners to a UIImageView . I found a solution
I have variable like float num = (x/y); I need to round up the
I have declared a time variable with value 23:59:59. So, I need to round
I need to round at only the top or bottom of a border container
I have an interesting issue where I need to round the result of an
I need to round some times. I would like to know how I can
I have a few double values..35.44, 35.66 . I need to round them, and
In my app i have a list view, in that i need to place
I need to round of numeric in my view. But there twig is used.
I have a BigDecimal calculation result which I need to round to the nearest

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.