Ios 如何从上下文绘制的图像中获取CGImageRef?

Ios 如何从上下文绘制的图像中获取CGImageRef?,ios,cocoa-touch,uikit,core-graphics,mask,Ios,Cocoa Touch,Uikit,Core Graphics,Mask,好的,使用coregraphics,我正在构建一个图像,稍后将用于CGContextClipToMask操作。它看起来如下所示: UIImage *eyes = [UIImage imageNamed:@"eyes"]; UIImage *mouth = [UIImage imageNamed:@"mouth"]; UIGraphicsBeginImageContext(CGSizeMake(150, 150)); CGContextRef context =

好的,使用coregraphics,我正在构建一个图像,稍后将用于
CGContextClipToMask
操作。它看起来如下所示:

    UIImage *eyes = [UIImage imageNamed:@"eyes"];
    UIImage *mouth = [UIImage imageNamed:@"mouth"];

    UIGraphicsBeginImageContext(CGSizeMake(150, 150));
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(context, 0, 0, 0, 1);
    CGContextFillRect(context, bounds);
    [eyes drawInRect:bounds blendMode:kCGBlendModeMultiply alpha:1];
    [mouth drawInRect:bounds blendMode:kCGBlendModeMultiply alpha:1];

    // how can i now get a CGImageRef here to use in a masking operation?

    UIGraphicsEndImageContext();
现在,正如你在评论中看到的,我想知道我将如何实际使用我建立的图像。我之所以在这里使用核心图形,而不仅仅是构建UIImage,是因为我创建的透明度非常重要。如果我只是从上下文中获取一个UIImage,当它用作掩码时,它将应用于所有内容。。。更重要的是,使用此方法使用部分透明遮罩会有任何问题吗?

您可以调用,它将返回UIImage对象。您可以保留并使用UIImage,或要求它提供其CGImage。

可能的副本
CGImageRef result = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext());