问题描述
|
如果使用设备颜色空间(RGBA,因此使用alpha),我认为背景是自动透明的。但是我不确定。
如何显式设置绘图画布或位图上下文的背景颜色,以确保创建时透明?
解决方法
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 ) ;
查看更多:http://oss.infoscience.co.jp/factor/docs.factorcode.org/content/word-CGContextSetRGBFillColor,core-graphics.html
, CGContextSetRGBFillColor(ctx,1); //black color
CGContextSetRGBFillColor(ctx,0); //transparent color - alpha set to null
, 此代码可以正常工作。
// transparent
CGContextSetRGBFillColor(cacheContext,0.0,0.0);
// image
CGImageRef cgImage = [[UIImage imageNamed:@\"img.png\"] CGImage];
CGContextDrawImage(cacheContext,self.bounds,cgImage);
CGContextFillRect(cacheContext,self.bounds);