Search code examples
iosios6core-image

CIFourfoldRotatedTile Core Image Filter


Following is the code that i am trying to apply to get CIFourfoldRotatedTile filter on image but i am getting a nil image in output.

CIContext *context = [CIContext contextWithOptions:nil];               // 1
CIImage *aimage = [CIImage imageWithCGImage:[UIImage imageNamed:@"Image1.png"].CGImage];
CIFilter *filter = [CIFilter filterWithName:@"CIFourfoldRotatedTile"];           // 3
[filter setValue:aimage forKey:kCIInputImageKey];
[filter setValue:[CIVector vectorWithCGPoint:CGPointMake(200, 200)] forKey:@"inputCenter"];
[filter setValue:[NSNumber numberWithFloat:2.0] forKey:@"inputAngle"];
[filter setValue:[NSNumber numberWithFloat:50] forKey:@"inputWidth"];

CIImage *result = [filter valueForKey:kCIOutputImageKey];              // 4
CGRect extent = [result extent];
CGImageRef cgImage = [context createCGImage:result fromRect:extent];
UIImage *finalImage = [UIImage imageWithCGImage:cgImage];
self.imgview.image = finalImage;

Don't know which parameter i am entering wrong. Please guide me on this. Thanks.


Solution

  • I have just checked your code and found that extent is infinite here i.e. you are getting a nil image. I just made a little change here, give extent to your frame

    CGRect extent = CGRectMake(0.0, 0.0, image.size.width, image.size.height); 
    

    OR

    CGRect extent = [aimage extent];
    

    and then try.