iOS图片保存相册

//TODO 调置滤镜
- (void) selectFilter2:(NSString *) nameLUT{
    // Create filter
    CIFilter *lutFilter = [CIFilter filterWithLUT:@"filter_lut_2" dimension:64];
    // Set parameter
    CIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"100"]];
    [lutFilter setValue:ciImage forKey:@"inputImage"];
    CIImage *outputImage = [lutFilter outputImage];
    CGColorSpaceRef spaceRef = CGColorSpaceCreateDeviceRGB();
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:(__bridge id _Nonnull)(spaceRef) forKey:kCIContextWorkingColorSpace];
    CIContext *context = [CIContext contextWithOptions:dic];
    CFRelease(spaceRef);
    
    CGImageRef imageRef = [context createCGImage:outputImage fromRect:outputImage.extent];
    newImage = [UIImage imageWithCGImage:imageRef];
    CFRelease(imageRef);
    //保存相册
    UIImageWriteToSavedPhotosAlbum(newImage,  self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
}

- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{    NSString *message;
    if (!error) {
        message = @"成功保存到相册";
        [self showStrAlert:@"成功保存到相册"];
    }else
    {
        [self showStrAlert:[NSString stringWithFormat:@"%@",error]];
    }
}

猜你喜欢

转载自wenxin2009.iteye.com/blog/2332742