0

I am new to Android development and I need to create this layout.

enter image description here

Any suggestion on how to do the cropping of the top part of the image with the circle would be greatly appreciated.

Thank you!

Edit: This not the same as the suggested duplicate as they are cropping the entire image into a circle and I only need the top part.

Digital Da
  • 891
  • 1
  • 10
  • 23

1 Answers1

0

This almost a duplicate of the linked question, so you can start from its answer to do what you want.

The relevant part to update is

canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
        bitmap.getWidth() / 2, paint);

If you read [the doc](http://developer.android.com/reference/android/graphics/Canvas.html#drawCircle(float, float, float, android.graphics.Paint)) of this method, you see that

  • the first param is the x coordinate of the center of the circle
  • the second param is the y coordinate of the center of the circle
  • the first coordinate is the radius of the circle

In the question above, the circle is drawn from the center of the bitmap. In your case, you want the center to be at e.g. 3/4 from the top.

Try this code instead

canvas.drawCircle(bitmap.getWidth() / 2, (bitmap.getHeight() / 4) * 3,
        bitmap.getWidth() / 2, paint);

and let us know.

Philippe A
  • 1,252
  • 9
  • 22