I'm working with filtering images that I'm taking with the camera. I pass the image I get from the camera through the below method. Which I have the returned UIImage
sent to a UIImageView
. For some reason when it passes through this method the image is getting rotated. What am I doing wrong?
- (UIImage *) applyFilterToImage:(UIImage *)image withFilter:(NSString *)filterName {
beginImage = [[[CIImage alloc] initWithImage:image] autorelease];
context = [CIContext contextWithOptions:nil];
filter = [CIFilter filterWithName:@"CISepiaTone" keysAndValues:kCIInputImageKey, beginImage, @"inputIntensity", [NSNumber numberWithFloat:0.8], nil];
outputImage = [filter outputImage];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg scale:1.0 orientation:UIImageOrientationUp];
CGImageRelease(cgimg);
return scaleAndRotateImage(newImg);
}
I found the answer. Can't believe you have to do all this to get it to work correctly, but it works.
https://stackoverflow.com/a/8229730/703910