How to create a ‘transparent circle inside rectangle’ shape in XML in Android?

I’ve been playing recently with something similar, and adapted it for you. All the magic is happening in the onDraw : public class FocusView extends View { private Paint mTransparentPaint; private Paint mSemiBlackPaint; private Path mPath = new Path(); public FocusView(Context context) { super(context); initPaints(); } public FocusView(Context context, AttributeSet attrs) { super(context, attrs); initPaints(); … Read more

What does PorterDuff.Mode mean in android graphics.What does it do?

Here’s an excellent article with illustrations by a Google engineer: http://ssp.impulsetrain.com/porterduff.html PorterDuff is described as a way of combining images as if they were “irregular shaped pieces of cardboard” overlayed on each other, as well as a scheme for blending the overlapping parts. The default Android way of composing images is PorterDuff.Mode.SRC_OVER, which equates to … Read more

Masking(crop) image in frame

Finally got the solution while changing mask image and using of Xfermode with Bitmap Mask ImageView mImageView= (ImageView)findViewById(R.id.imageview_id); Bitmap original = BitmapFactory.decodeResource(getResources(),R.drawable.content_image); Bitmap mask = BitmapFactory.decodeResource(getResources(),R.drawable.mask); Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Config.ARGB_8888); Canvas mCanvas = new Canvas(result); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mCanvas.drawBitmap(original, 0, 0, null); mCanvas.drawBitmap(mask, 0, 0, paint); paint.setXfermode(null); mImageView.setImageBitmap(result); mImageView.setScaleType(ScaleType.CENTER); … Read more