Bitmap 이미지 모서리 round 처리하기


코드 사용

Button button2 = (Button) findViewById(R.id.button2); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Bitmap bm = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); imageView.setImageBitmap(getRoundedCornerBitmap(bm, 20)); } });

호출

/* 비트맵 모서리 둥글게*/
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int px) {
	Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.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 = px;
	paint.setAntiAlias(true);
	canvas.drawARGB(0, 0, 0, 0);
	paint.setColor(color);
	canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
	paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
	canvas.drawBitmap(bitmap, rect, rect, paint);
	return output;
}


변경 전


변경 후


+ Recent posts