简体   繁体   中英

CIFilter output width and height is zero

I'm trying to filter an image I got from the imagePicker. The original image stores absolutely fine with my code, but when I try to filter it with CIFilter, the resulting UIImage "filteredImage" is 0x0 pixels in size.

I'm posting the complete function here, it's the image pickers delegate method.

UPDATE: Filter "CISepiaTone" works and gives me an image with correct dimensions. But CIColorMonochrome is available on iOS too, I checked by asking CIFilter for available filter options.

UPDATE 2: Found it - the inputColor Parameter has to be of type CIColor not UIColor, I overlooked that in the reference.

- (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];    
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM