I want to achieve a circular shape only with PorterDuffXfermode(not other ways).i try the following code but it does not work and the result is still rectangular. where is the wrong?
private Bitmap getCropped(Bitmap bitmap) {
Bitmap image = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.CYAN);
Path path = new Path();
path.addCircle((float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2, (float) bitmap.getWidth() / 2, Path.Direction.CW);
canvas.drawPath(path, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
canvas.drawBitmap(bitmap, rect, rect, paint);
return image;
}