Android Bitmap Corner Round getRoundedCornerBitmap(Bitmap bitmap, float roundPx)

Here you can find the source of getRoundedCornerBitmap(Bitmap bitmap, float roundPx)

Description

get Rounded Corner Bitmap

License

Apache License

Parameter

Parameter Description
bitmap a parameter
roundPx a parameter

Declaration

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) 

Method Source Code

//package com.java2s;
/**//www .  ja  v a  2 s.  c o  m
 * Copyright (c) 2013-2014, Rinc Liu (http://rincliu.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import android.graphics.Bitmap;

import android.graphics.Bitmap.Config;

import android.graphics.Canvas;

import android.graphics.Paint;

import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;

public class Main {
    /**
     * @param bitmap
     * @param roundPx
     * @return
     */
    public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
        Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888);
        Canvas canvas = new Canvas(output);
        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, w, h);
        final RectF rectF = new RectF(rect);
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        return output;
    }
}

Related

  1. getRoundedCornerBitmap(Bitmap bitmap, float roundPx)
  2. getRoundedCornerBitmap(Bitmap bitmap, int roundPx)
  3. getRoundBitmapFromUrl(String url, int pixels)
  4. toRoundCorner(Bitmap bitmap, int pixels)
  5. toRoundCorner( BitmapDrawable bitmapDrawable, int pixels)
  6. getRoundedCornerBitmap(Bitmap bitmap, int maxHeight, int pixels)
  7. getRoundedRectBitmap(Bitmap bitmap, int pixels)
  8. toRoundBitmap(Bitmap bitmap)
  9. toRoundBitmap(Bitmap bitmap)