Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

drf1229

macrumors regular
Original poster
Jun 22, 2009
237
0
I was curious if there is a way to crop a UIImage with a circle, so as to cut out only a person's head in a picture, etc. I've had success with CGImageCreateWithImageInRect() but I was curious if there was a way to do this with a circle. I think I need to create a mask but I'm not sure. Any advice is greatly appreciated!
 
If your original bitmap is 100 x 100, and the smallest rectangle that can enclose the circle is 50 x 50, then you can take that small bitmap and "cut the corners off" in a couple of different ways.

The best way I can think of is to clip your graphics context. Basically, you have this small bitmap and you are going to draw that into a graphics context, but before you draw you tell the context where it "won't be drawing". These spots will show up as transparent (the rounded corners).

You can clip your graphics context with a path (draw the circle with code), or with a bitmap mask. A mask would look like a black page with a white circle. The white part is drawn and the black part is not.

Take a look at the Quartz 2D Programming Guide and there will be more about all of this.
 
Thanks for your reply! I'll look at the Quartz 2D guide
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.