开发者

Drawing a rounded drop shadow with Quartz

I am trying to draw a drop shadow underneath an image to which I apply rounded corners, but I have 2 problems:

  1. The drop shadow only appears underneath the non-rounded area of the rounded image and not underneath the bottom rounded corners as one would get if applying a drop shadow in photoshop.

  2. Using the same settings as in photoshop (a 2 y-axis offset, 1 blur and 85% black) results in a much darker shadow which does not appear as blurred as it should.

Any help would be appreciated please.

float myColorValues[] = {0, 0, 0, 0.85};
    CGColorRef myColor = CGColorCreate(colorSpace, myColorValues);
    CGContextSetShadowWithColor(context, CGSizeMake(0, -2), 2, myColor);

    // Draw a round corner path
    CGContextBeginPath(context);
    CGRect rect = CGRectMake(0, 0, 68, 68);
    addRoundedRectToPath(context, rect, cornerWidth, cornerHeight);
    CGContextClosePath(context);
    CGContextClip(开发者_运维技巧context);

    CGContextDrawImage(context, CGRectMake(1, 2, 70, 70), imageScaledAndCropped);


The solution is to draw a rounded bezier path underneath the image and to apply the shadow to that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜