我正在尝试将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
分配给图像视图,则显示正常。
那我在这里做错了什么?我想用这个代码来处理截图,但是我用照片试了一下,得到了相同的(零)结果。