0

I have an application which takes picture from camera .And normally this pictures have either rectangle shapes or square shapes.But due to make these pictures circular in shape i limited the shape to only square.So now my problem is to make this square picture into a circular shape having radius of half of width or height.And the clipped part should be removed from the picture.

Its same like making a circle from the square which touches midpoint of all of the faces of square. I don't have any experience with canvas or other in built drawing functions.

enter image description here

For example i have square at first now i want to make image circular such that parts pointed by arrow should get clipped from image.

Note:as i have to work with camera images .quality is crucial factor.So please suggest the possible ways that will not affect the pixel quality and other important factors.

kaushal trivedi
  • 3,405
  • 3
  • 29
  • 47

1 Answers1

1

You can do it by masking the image with your desired shape, see this post for detailed info. example code:

Resources resources = context.getResources();
Bitmap original = BitmapFactory.decodeResource(resources,R.drawable.original);
Bitmap mask = BitmapFactory.decodeResource(resources,R.drawable.mask);
Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Config.ARGB_8888);
Canvas c = new Canvas(result);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
c.drawBitmap(original, 0, 0, null);
c.drawBitmap(mask, 0, 0, paint);
paint.setXfermode(null);
imageView.setImageBitmap(result);
Axarydax
  • 16,353
  • 21
  • 92
  • 151
  • what is R.drawable.mask here.Is it a hollow ring or just another drawable having circluar shape.Can you specify some details. And ya thnx for sharing the code sample.:) – kaushal trivedi Feb 10 '13 at 09:28
  • in this sample it's a circular shape, but it would be better if you drawn it yourself in dimensions of the captured image from camera (e.g. 1600x1200) – Axarydax Feb 10 '13 at 09:29