解决CIFilter滤镜后图片大小和方向发生变化

调用contextWithOptions:和createCGImage: fromRect:方法创建CIContext。与以往不同的地方是CIImage没有frame与bounds属性;只有extent属性。你将非常频繁的使用这个属性作为createCGImage: fromRect:方法的第二个参数

摘自:http://www.cocoachina.com/industry/20140115/7703.html

    UIImage *image = [UIImage imageNamed:@"IMG_0027.JPG"];
    
    CIContext *context = [CIContext contextWithOptions:nil];
    //黑白滤镜
    CIImage *beginImage = [CIImage imageWithCGImage:image.CGImage];
    CIFilter *filter = [CIFilter filterWithName:@"CIPhotoEffectNoir"
                                  keysAndValues: kCIInputImageKey, beginImage, nil];

    CIImage *outputImage = [filter outputImage];
    CGImageRef cgimg = [context createCGImage:outputImage fromRect:[beginImage extent]];
    UIImage *newImage = [UIImage imageWithCGImage:cgimg scale:image.scale orientation:image.imageOrientation];
    _cropper.image = newImage;
    CGImageRelease(cgimg);

 

posted @ 2015-05-28 18:31  嗷大喵  阅读(1094)  评论(0编辑  收藏  举报