开发者

iPhone: Create CGLayer with gradient point and transparent background

I would like to create a CGLayer, contains a point with gradient in boundary. Because I will use this layer to draw multiple points o开发者_运维百科n the main screen.

This is my code: CGRect r = CGRectMake(0, 0, 64, 64); textureLayer = CGLayerCreateWithContext(context, r.size, NULL); CGContextRef textureContext = CGLayerGetContext(textureLayer);

CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGFloat colors[] =
{
    0.0, 0.0, 0.0, 1.0,
    1.0, 1.0, 1.0, 1.0 
};
gradient = CGGradientCreateWithColorComponents(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));
CGColorSpaceRelease(rgb);

CGPoint start, end;
start = end = CGPointMake(32, 32);
CGFloat startRadius = 20;
CGFloat endRadius = 30;
CGContextSaveGState(textureContext);
CGGradientDrawingOptions options = 0 | kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
CGContextDrawRadialGradient(textureContext, gradient, start, startRadius, end, endRadius, options);
CGContextRestoreGState(textureContext);

I got this result:

iPhone: Create CGLayer with gradient point and transparent background

It is correct. But when I draw on main screen, not the stroke like I expect, this is the result:

iPhone: Create CGLayer with gradient point and transparent background

I think the problem is the white background in my CGLayer. How I can make that background be transparent?

Thank for your help.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜