1

我正在尝试将 CIFilter 应用于从UIImagePickerController. 这是我正在使用的代码:

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

    [picker dismissViewControllerAnimated:YES completion:nil];

    UIImage *userImage = info[UIImagePickerControllerOriginalImage];
    UIImage *croppedImage = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(userImage.CGImage, CGRectMake(0, 320, 640, 640))];

    CIContext *context = [CIContext contextWithOptions:nil];
    CIImage *img = [CIImage imageWithCGImage:croppedImage.CGImage];
    CIFilter *adjustFilter = [CIFilter filterWithName:@"CILineOverlay"];

    [adjustFilter setDefaults];
    [adjustFilter setValue:img forKey:kCIInputImageKey];
    [adjustFilter setValue:[NSNumber numberWithFloat:1.0] forKey:@"inputNRSharpness"];
    CIImage *adjustedImage = [adjustFilter valueForKey:kCIOutputImageKey];
    UIImage *newImage = [UIImage imageWithCIImage:[context createCGImage:adjustedImage fromRect:adjustedImage.extent]];

    NSLog(@"%@", newImage);

    self.myImageView.image = newImage;

}

现在,当应用过滤器的过程完成时(没有弹出错误),图像视图中看不到任何图像(尽管控制台会记录<UIImage: 0x8b91810>)。如果我跳过处理部分并将未过滤croppedImage的内容分配给图像视图,则显示效果很好。

那么我在这里做错了什么?我想使用此代码来处理屏幕截图,但我已经用照片尝试过它并得到了相同的(零)结果。

4

0 回答 0