【发布时间】:2011-05-30 13:04:37
【问题描述】:
如果我使用设备颜色空间(RGBA,因此使用 alpha),我假设背景是自动透明的。但我不确定。
如何明确设置我的绘图画布或位图上下文的背景颜色,以确保它在创建时是透明的?
【问题讨论】:
标签: iphone cocoa-touch ios ipad core-graphics
如果我使用设备颜色空间(RGBA,因此使用 alpha),我假设背景是自动透明的。但我不确定。
如何明确设置我的绘图画布或位图上下文的背景颜色,以确保它在创建时是透明的?
【问题讨论】:
标签: iphone cocoa-touch ios ipad core-graphics
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 ) ;
【讨论】:
这段代码可以正常工作。
// 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);
【讨论】: