经过CIFilter后,iOS UIImage会被旋转

时间:2012-03-28 18:56:42

标签: ios uiimageview uiimage core-image

我正在处理我正在使用相机拍摄的图像。我通过以下方法传递了从相机获得的图像。我已将退回的UIImage发送给UIImageView。出于某种原因,当它通过这种方法时,图像会旋转。我做错了什么?

    - (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 个答案:

答案 0 :(得分:2)

我找到了答案。不能相信你必须做所有这一切才能让它正常工作,但它确实有效。

https://stackoverflow.com/a/8229730/703910