Home > Tutorials > Image Processing – Image with Round Corner

Image Processing – Image with Round Corner

One more guide for you to decorate your image: creating image with rounded corner 🙂

Form this original beauty:

Original Image

Original Image

This is the effect:

Round at 45

Round at 45

Pretty simple trick!

I just apply a black rounded corner rectangle to the image.

Here the implementation:

    public static Bitmap roundCorner(Bitmap src, float round) {
    	// image size
    	int width = src.getWidth();
    	int height = src.getHeight();
    	// create bitmap output
        Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);
        // set canvas for painting
        Canvas canvas = new Canvas(result);
        canvas.drawARGB(0, 0, 0, 0);

        // config paint
        final Paint paint = new Paint();

        // config rectangle for embedding
        final Rect rect = new Rect(0, 0, width, height);
        final RectF rectF = new RectF(rect);

        // draw rect to canvas
        canvas.drawRoundRect(rectF, round, round, paint);

        // create Xfer mode
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        // draw source image to canvas
        canvas.drawBitmap(src, rect, rect, paint);

        // return final image
        return result;

Hope you like it!

Pete Houston

  1. Drimoliyan
    March 18, 2015 at 5:40 pm

    if u get error on Src_in cannot be resolved

    Use this:—–>

    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN));

    INsted oF:—->

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));

  2. Prince
    June 30, 2014 at 1:02 pm

    If anyone having issue with “SRC_IN cannot be resolved or is not a field”, you need to import Mode as import android.graphics.PorterDuff.Mode; it will solve your issue.

  3. May 28, 2014 at 5:07 pm

    Nice article……

  4. June 21, 2013 at 3:45 am

    Hy Every one , i have resolved the issue of SRC_IN.
    use PorterDuff.Mode.SRC_IN instead of Mode.SRC_IN

  5. Umesh Moradiya
    April 25, 2013 at 12:48 pm

    just import “import android.graphics.PorterDuff.Mode;” and hope it will help you……

  6. Lavanya
    March 1, 2013 at 1:11 pm

    I’m having the same problem with code in “SRC_IN cannot be resolved or is not a field”.
    Please help me .

  7. raj
    October 6, 2012 at 7:32 pm

    Hi…your tutorial is really helpful for me…Please keep adding …

  8. Astur
    September 20, 2012 at 8:28 pm

    The same problem happens to me.

    Pls, help us with this issue.

  9. Naresh
    September 6, 2012 at 3:31 pm

    I have problem with code please help me .
    In my code
    SRC_IN cannot be resolved or is not a field.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: