Clip a CPImage into a circle or other shape
I have a rectangular CPImage setup like so
var img = [[CPImage al开发者_开发问答loc] initWithContentsOfFile:"Resources/img.jpg""];
I'd like to display that in my CPView subclass in a circle with the part of the image clipped (what lies outside the eclipse) remaining transparent. I tried this:
- (void)drawRect:(CGRect)aRect
{
var path = [CPBezierPath bezierPathWithOvalInRect:aRect];
[[CPColor colorWithPatternImage:img] set];
[path fill];
}
but I just get a black circle.
The problem here is that you can't use an image to fill with (yet) in Cappuccino. So it'll just turn out black like you discovered, even that the commands you're using are technically correct. I'm not aware of a work around but you could try posting to the Cappuccino user list and see if anyone is working on this feature right now.
精彩评论