Having followed a tutorial on Ray Wenderlich’s site with success, I decided to try and manipulate what I learned and apply it towards a CITransition, particularly CIDissolveTransition. However, I can’t seem to get the image to appear even after cross-referencing what I’ve learned against Apple’s own filter documentation (which, I gotta say, are dated and incredibly difficult to adapt outside of their own convoluted examples). Here is what I have so far:
NSURL *url = [NSURL fileURLWithPath:imagePath];
NSURL *url2 = [NSURL fileURLWithPath:image2Path];
CIContext *context;
CIFilter *filter;
CIImage *beginImage, *targetImage;
UIImageView *mainImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[self addSubview:mainImage];
beginImage = [CIImage imageWithContentsOfURL:url];
targetImage = [CIImage imageWithContentsOfURL:url2];
if(context == nil)
{
NSLog(@"Creating Context");
context = [CIContext contextWithOptions:nil];
}
if(filter == nil) {
NSLog(@"Creating filter");
filter = [CIFilter filterWithName:@"CIDissolveTransition" keysAndValues:@"inputImage", beginImage, @"inputTargetImage", targetImage, @"inputTime", [NSNumber numberWithFloat:0.5], nil];
}
CIImage *outputImage = [filter outputImage];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg];
[mainImage setImage:newImg];
All I’ve been getting is a black screen where mainImage should be displaying. The ultimate goal is to be able to cycle through a sequence of images with this dissolve effect using a slider (which I am only assuming will work), but I can’t even get this static image to display. Any help will be greatly appreciated.
Your call to filterWithName:keysAndValues: is returning nil because iOS doesn’t know how to make a CIDossolveTransition filter.
Core Image for iOS doesn’t support all the filters that Core image for Mac OS does. See this answer
You can read Apple’s Core image Filter reference and see which filters are supported in iOS, but the bad news is that transitions didn’t make the cut for iOS 5. The only filter available in iOS 5 that deals with compositing is CISourceOverCompositing, which probably isn’t very interesting to you.