1

In theory, let's say I have a View that lookes like this:

enter image description here

it's made in 'onDraw' by methods like 'drawCircle', 'drawRect', etc...

...And now let's say I have an imaginable Circle(well, a Circle object that I don't paint on the View) and I want the view to be filled with some color EXCEPT inside the imaginable Circle... so I want it to look like this:

enter image description here

How can I achieve this???

martin k.
  • 156
  • 3
  • 15

1 Answers1

1

Not sure exactly how to do it, but look in to PorterDuff. Take a look at this question

Here is an example I found at ProgramCreek (exapmle #8):

private Bitmap getRoundedCornerBitmap(Bitmap bitmap){
  Bitmap output=Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),Config.ARGB_8888);
  Canvas canvas=new Canvas(output);
  final Paint paint=new Paint();
  final Rect rect=new Rect(0,0,bitmap.getWidth(),bitmap.getHeight());
  final RectF rectF=new RectF(rect);
  paint.setAntiAlias(true);
  canvas.drawARGB(0,0,0,0);
  paint.setColor(0xFFFFFFFF);
  canvas.drawRoundRect(rectF,roundPixels,roundPixels,paint);
  paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
  canvas.drawBitmap(bitmap,rect,rect,paint);
  return output;
}
Community
  • 1
  • 1
Chad Bingham
  • 32,650
  • 19
  • 86
  • 115