0
imagePicker에서 가져온 이미지를 필터링하려고합니다. 원본 이미지는 내 코드와 함께 완벽하게 저장되지만 CIFilter로 필터링하려고하면 결과로 생성되는 UIImage "filteredImage"크기는 0x0 픽셀입니다.CIFilter 출력 너비와 높이가 0입니다.
여기 전체 기능을 게시하고 있습니다. 이미지 선택 프로그램 대리인 메소드입니다.
업데이트 : 필터 "CISepiaTone"필터가 작동하고 정확한 크기의 이미지가 표시됩니다. 하지만 CIColorMonochrome도 iOS에서 사용할 수 있습니다. 사용 가능한 필터 옵션을 CIFilter에 요청하여 확인했습니다.
UPDATE 2 : 발견했습니다. inputColor 매개 변수는 UIColor가 아닌 CIColor 유형이어야합니다. 참조에서 간과 할 수 없습니다.
- (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];
}