about uscontact

[Android] BitmapHelper Class

Author: zemna
Date: April 17, 2021
Share this:

개요

BitmapHelper 클래스는 인자로 넘겨받은 비트맵 이미지의 모서리를 둥글게 처리한 비트맵으로 변경하여 리턴하는 클래스이다.

소스

[code lang="java"] import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Bitmap.Config; import android.graphics.PorterDuff.Mode;

public class BitmapHelper {

public static Bitmap getRoundedCornerBitmap(Context context, Bitmap bitmap , int roundLevel) {

Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output);

final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = convertDipsToPixels(context, roundLevel);

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; }

public static int convertDipsToPixels(Context context, int dips) {

final float scale = context.getResources().getDisplayMetrics().density; return (int) (dips * scale + 0.5f); }

} [/code]

Share this:

Leave a Reply

Your email address will not be published.

ZEMNA.NET

Professional software development agency estalished in Indonesia. We offers website setup, web application development, fulfillment service, and etc.
Follow us
Follow us to get latest news and tutorials.
2022 - Copyright, All Rights Reserved, Made by ZEMNA.NET with ❤️
magnifiercrossmenu