Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to properly apply Core Image filter

Im having a trouble with Core image. what I'm doing is getting an image from a UIImageView and then use some code i found in tutorials (I'm new to core Image) but then I want to put the sepia image back into the same same UIImageView when ever I try to put the new image into the view it just disappears I have tested to see if the image view contains an image and it does but it is not visible. any suggestions on what to do?

EDIT: okay I got the sepia filter to work so then I tried posterize and i had the same problem the image just disappears. Here is the code:

CIImage *beginImage = [CIImage imageWithCGImage:[image_view.image CGImage]];
context = [CIContext contextWithOptions:nil];
filter = [CIFilter filterWithName:@"CIColorPosterize" keysAndValues:kCIInputImageKey, beginImage,@"inputLevels",[NSNumber numberWithFloat:0.8], nil];
CIImage *outputImage = [filter outputImage];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg];
[image_view setImage:newImg];
CGImageRelease(cgimg);
like image 384
Sage Washabaugh Avatar asked Jun 22 '12 00:06

Sage Washabaugh


1 Answers

Try something like this (let say you have an UIImageView *myImageView)

CIImage *beginImage = [CIImage imageWithCGImage:[myImageView.image CGImage]];
CIContext *context = [CIContext contextWithOptions:nil];

CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone" keysAndValues: kCIInputImageKey, beginImage, @"inputIntensity", [NSNumber numberWithFloat:0.8], nil];
CIImage *outputImage = [filter outputImage];

CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg];

[myImageView setImage:newImg];

CGImageRelease(cgimg);
like image 132
Ladislav Avatar answered Sep 28 '22 04:09

Ladislav