I'm trying to get the output of the CoreImage CIRandomGenerator filter, with the following code:

CIContext *context = [CIContext contextWithOptions:nil];

CIFilter *randomNoise = [CIFilter filterWithName:@"CIRandomGenerator"];
[randomNoise setDefaults];

CIImage *output = randomNoise.outputImage;

// This returns nil
CGImageRef ref = [context createCGImage:output
                               fromRect:output.extent];
self.photoView.image = [UIImage imageWithCGImage:ref];
CGImageRelease(ref);

However, the createCGImage:fromRect: always returns a nil CGImageRef.

What am I doing wrong?

有帮助吗?

解决方案

You need to be sure to crop the extent so that it's not infinite.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top