Code example for Canvas

Methods: drawARGBdrawBitmapdrawRoundRect

0
	private static final int ROUND_DIPS = 8;
 
	public static Bitmap getRoundedCornerBitmap(Context context, Bitmap bitmap, int color) {
	    
		Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
	    Canvas canvas = new Canvas(output);
 
	    color = 0xff424242;  // FIXME
	    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, ROUND_DIPS);
 
	    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 Bitmap createRoundedBottomBitmap(Context context, int width, int height, int color) {
Experience pair programming with AI  Get Codota for Java