如何从上下文绘制图像获取CGImageRef? [英] How to get a CGImageRef from Context-Drawn Images?

查看:445
本文介绍了如何从上下文绘制图像获取CGImageRef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定使用核心,我建立一个图像,稍后将用于 CGContextClipToMask 操作。它看起来像下面这样:

Ok using coregraphics, I'm building up an image which will later be used in a CGContextClipToMask operation. It looks something like the following:

    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,当它被用作掩码,它将只适用于一切...更进一步,使用这种方法使用部分透明的掩码,我会有任何问题吗?

Now, as you can see by the comment, I'm wondering how I'm actually going to USE the image I've built up. The reason why I'm using core graphics here and not just building up a UIImage is that the transparency I'm creating is very important. If I just grab a UIImage from the context, when it's used as a mask, it will just apply to everything... Further to the point, will I have any problems using a partially-transparent mask using this method?

推荐答案

CGImageRef result = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext());

这篇关于如何从上下文绘制图像获取CGImageRef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆