开发者

Clip a CPImage into a circle or other shape

开发者 https://www.devze.com 2023-01-08 23:24 出处:网络
I have a rectangular CPImage setup like so var img = [[CPImage al开发者_开发问答loc] initWithContentsOfFile:\"Resources/img.jpg\"\"];

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消