The code is:
- (void)renderText
{
// release the old image
[textImage release];
textImage = nil;
//First line to change
NSGraphicsContext *cContext = [NSGraphicsContext currentContext];
// render the text objects into the context
CGContextClearRect(bitmapContext,layerRect);
NSGraphicsContext *graphicsContext = [[NSGraphicsContext graphicsContextWithGraphicsPort:bitmapContext flipped:NO] retain];
[NSGraphicsContext setCurrentContext:graphicsContext];
[textObjects makeObjectsPerformSelector:@selector(renderIntoCurrentContext)];
if(layer)
{
// we can render using the CGLayer
textImage = [[CIImage alloc] initWithCGLayer: layer];
} else {
// create a CIImage from the bitmap context by the way of creating a CGImage - this causes a copy !
CGImageRef bitmapImage = nil;
bitmapImage = CGBitmapContextCreateImage(bitmapContext);
if(!bitmapImage)
return;
textImage = [[CIImage alloc] initWithCGImage: bitmapImage];
CGImageRelease(bitmapImage); // now retained by the CIImage
}
[invertFilter setValue:textImage forKey:@"inputImage"];
[blurFilter setValue:[invertFilter valueForKey:@"outputImage"] forKey:@"inputImage"];
[compositeFilter setValue:textImage forKey:@"inputImage"];
[compositeFilter setValue:[blurFilter valueForKey:@"outputImage"] forKey:@"inputBackgroundImage"];
// Second line to change
[NSGraphicsContext setCurrentContext:cContext];
}
View comments