iOS UIImage being rotated when after going through

2019-05-14 00:16发布

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);
}

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-05-14 00:29

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

查看更多
登录 后发表回答