How to get CGImageRef from context-sensitive images?

Well, using coregraphics, I create an image that will be used later in the CGContextClipToMask operation. It looks something like this:

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

Now, as you can see from the commentary, I wonder how I'm actually going to use the image I created. The reason I use the main graphics here, and not just create a UIImage, is because the transparency I create is very important. If I just take a UIImage from the context, when it is used as a mask, it will apply to everything ... In addition to this, will I have problems using a partially transparent mask using this method?

+8
ios cocoa-touch uikit core-graphics mask
source share
2 answers
 CGImageRef result = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext()); 
+12
source share

You can call the UIGraphicsGetImageFromCurrentImageContext function , which will return a UIImage object. You can hold and use UIImage or request it for CGImage.

+2
source share

All Articles