Setting A CGContext Transparent Background

后端 未结 8 753
长发绾君心
长发绾君心 2020-12-08 09:15

I am still struggling with drawing a line with CGContext. I have actually go to line to draw, but now I need the background of the Rect to be transparent so the existing ba

8条回答
  •  旧巷少年郎
    2020-12-08 10:00

    you can create a image context with this code:

    cacheContext = CGBitmapContextCreate (cacheBitmap, size.width, size.height, 8, bitmapBytesPerRow, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
    CGContextSetRGBFillColor(cacheContext, 0, 0, 0, 0);
    CGContextFillRect(cacheContext, (CGRect){CGPointZero, size});
    

    the key is kCGImageAlphaPremultipliedLast.

提交回复
热议问题