【问题标题】:How to set a background color for the drawing canvas created with CGBitmapContextCreate()?如何为使用 CGBitmapContextCreate() 创建的绘图画布设置背景颜色?
【发布时间】:2011-05-30 13:04:37
【问题描述】:

如果我使用设备颜色空间(RGBA,因此使用 alpha),我假设背景是自动透明的。但我不确定。

如何明确设置我的绘图画布或位图上下文的背景颜色,以确保它在创建时是透明的?

【问题讨论】:

标签: iphone cocoa-touch ios ipad core-graphics


【解决方案1】:
CGContextSetRGBFillColor(ctx, 0, 0, 0, 1); //black color

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

【讨论】:

    【解决方案2】:
    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

    【讨论】:

      【解决方案3】:

      这段代码可以正常工作。

       // 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);
      

      【讨论】:

        猜你喜欢
        • 2021-11-29
        • 1970-01-01
        • 1970-01-01
        • 2013-08-02
        • 1970-01-01
        • 1970-01-01
        • 2016-03-17
        • 1970-01-01
        • 2016-01-02
        相关资源
        最近更新 更多