如何为使用CGBitmapContextCreate创建的绘图画布设置背景色?

问题描述

| 如果使用设备颜色空间(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);
    

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...