0

我正在尝试过滤从 imagePicker 获得的图像。原始图像在我的代码中存储得非常好,但是当我尝试使用 CIFilter 对其进行过滤时,生成的 UIImage“filteredImage”大小为 0x0 像素。

我在这里发布了完整的功能,它是图像选择器委托方法。

更新:过滤器“CISepiaTone”有效,并为我提供了尺寸正确的图像。但是 CIColorMonochrome 在 iOS 上也可用,我通过询问 CIFilter 来检查可用的过滤器选项。

更新 2:找到它 - inputColor 参数必须是 CIColor 类型而不是 UIColor,我在参考中忽略了这一点。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    // Filter the image
    CIImage *filterImage = [[CIImage alloc] initWithCGImage:image.CGImage];
    CIFilter *colorMono = [CIFilter filterWithName:@"CIColorMonochrome"];
    [colorMono setDefaults];
    [colorMono setValue:filterImage forKey:@"inputImage"];
    [colorMono setValue:[UIColor yellowColor] forKey:@"inputColor"];

    CIImage *outputImage = [colorMono outputImage];
    CIContext *con = [CIContext contextWithOptions:nil];
    CGImageRef filteredImageRef = [con createCGImage:outputImage fromRect:[outputImage extent]];
    UIImage *filteredImage = [UIImage imageWithCGImage:filteredImageRef scale:1.0f orientation:UIImageOrientationUp];
    // filteredImage dimensions are 0x0 px here!

    CGImageRelease(filteredImageRef);

    // Save image in imageStore
    CFUUIDRef uniqueId = CFUUIDCreate(kCFAllocatorDefault);
    CFStringRef uniqueIdStringRef =  CFUUIDCreateString(kCFAllocatorDefault, uniqueId);

    NSString *key = (__bridge NSString *)uniqueIdStringRef;
    [[FPImageStore sharedStore] setImage:filteredImage forKey:key];
    imageKey = key;

    CFRelease(uniqueId);
    CFRelease(uniqueIdStringRef);

    // Dismiss imagePicker viewController
    [self dismissViewControllerAnimated:YES completion:nil];    
}
4

1 回答 1

0

inputColor 参数的类型必须是 CIColor 而不是 UIColor,我在参考中忽略了这一点。

于 2012-06-24T02:21:33.010 回答