开发者

How to set a background color for the drawing canvas created with CGBitmapContextCreate()?

I 开发者_JAVA技巧assume that the background is transparent automatically if I use the device color space (RGBA, so with alpha). But I'm not sure.

How can I set the background color of my drawing canvas or bitmap context explicitely to make sure it is transparent when it is created?


CGContextSetRGBFillColor(ctx, 0, 0, 0, 1); //black color

CGContextSetRGBFillColor(ctx, 0, 0, 0, 0); //transparent color - alpha set to null


CGContextSetRGBFillColor ( c red green blue alpha -- )

USING: alien.c-types alien.syntax core-graphics.types ;
IN: core-graphics
FUNCTION: void CGContextSetRGBFillColor ( CGContextRef c, CGFloat red, CGFloat green, CGFloat blue,CGFloat alpha ) ;

see more: http://oss.infoscience.co.jp/factor/docs.factorcode.org/content/word-CGContextSetRGBFillColor,core-graphics.html


This code will work fine.

 // transparent
 CGContextSetRGBFillColor(cacheContext, 0.0, 0.0, 0.0, 0.0);
 // image
 CGImageRef cgImage = [[UIImage imageNamed:@"img.png"] CGImage];
 CGContextDrawImage(cacheContext, self.bounds, cgImage);
 CGContextFillRect(cacheContext, self.bounds);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜