2011-12-28 3 views
3

안녕하세요. 일부 필터를 사용하고 있습니다. 이들 모두가 CISepiaTone 및 CIHueAdjust와 같이 정상적으로 작동하는 것은 아닙니다. 최근 CIGLoom 필터를 시도하고 null 이미지를 반환합니다.CIFilter가 제대로 작동하지 않습니다. null 이미지를 반환합니다.

-(UIImage*)getGloom:(UIImage*)anImage{ 
    CGImageRef cgimage = anImage.CGImage; 
    CIImage *cimage = [CIImage imageWithCGImage:cgimage]; 
    CIFilter *filter = [CIFilter filterWithName:@"CIGloom"]; 
    [filter setDefaults]; 
    [filter setValue: cimage forKey: @"inputImage"]; 
    [filter setValue: [NSNumber numberWithFloat: 25] 
      forKey: @"inputRadius"]; 
    [filter setValue: [NSNumber numberWithFloat: 0.75] 
      forKey: @"inputIntensity"]; 

    CIContext *context = [CIContext contextWithOptions:nil]; 
    CIImage *ciimage = [filter outputImage]; 
    CGImageRef cgimg = [context createCGImage:ciimage fromRect:[ciimage extent]]; 
    UIImage *uimage = [UIImage imageWithCGImage:cgimg scale:1.0f orientation:UIImageOrientationUp]; 

    CGImageRelease(cgimg); 

    return uimage; } 

내가 실제로 올해 techtalk 세계 투어에서이 코드를 가지고 있으며 CISepiaTone을 위해 작동하지만 그것은 단지 cigloom 실패합니다. cicolorposterize, ciedges 및 일부 다른. 왜 아무도 몰라요? 또는이 NUll 이미지를 어떻게 감당할 수 있습니까?

답변

5

CIGloom 및 내가 겪고있는 다른 문제는 아직 iOS에서 지원되지 않습니다. 이 배열 결과를 사용하여 사용할 수있는 필터를 확인할 수 있습니다.

4

예, 일부 필터는 아직 iOS에서 사용할 수없는 것 같습니다. 문서를 읽을 때도 재미있는 경험을했습니다. 그러나 위의 스피커처럼 코드를 사용하여 iOS 용으로 사용할 수있는 필터를 확인할 수 있습니다. 일부 필터 (예 : Civingette)는 설명서에서 찾지 못했지만 5.1에서 iOS에 사용할 수있는 각 필터의 ​​값 매개 변수를 가져 오려고했습니다.

NSArray *supportedFilters = [CIFilter filterNamesInCategory:kCICategoryBuiltIn]; 
for (CIFilter *filter in supportedFilters) { 
    NSString *string = [NSString stringWithFormat:@"%@",[[CIFilter filterWithName:(NSString *)filter] inputKeys]]; 
    NSLog(@"%@ %@", filter, string); 
} 

응답 : 미래에 당신은 아마 문서를 읽으려면 (또는 누군가가 이미 이었나 알고 당신이 그것에 대해 자세한 내용을보실 수 있습니다) 것을

 
... 
2012-04-19 14:02:55.597 ImageFiltering[12190:707] CIVibrance (
    inputImage, 
    inputAmount 
) 
2012-04-19 14:02:55.599 ImageFiltering[12190:707] CIVignette (
    inputImage, 
    inputIntensity, 
    inputRadius 
) 
2012-04-19 14:02:55.601 ImageFiltering[12190:707] CIWhitePointAdjust (
    inputImage, 
    inputColor 
) 
... 

참고. 이전에 언급했듯이 일부 필터에 대한 설명서를 찾지 못했기 때문에이 문제를 해결하기 위해 탐정을 사용하고 있습니다.

 
- (void)displayVingetteFilterWithImage{ 
    // Get image and set it as CIImage 
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image_1" ofType:@"jpg"]; 
    NSURL *fileNameAndPath = [NSURL fileURLWithPath:filePath]; 
    CIImage *image = [CIImage imageWithContentsOfURL:fileNameAndPath]; 

    // Create context 
    CIContext *imageContext = [CIContext contextWithOptions:nil]; 

    // Set filter to image, in this case CIVignette, knowing it uses inputImage, inputIntensity and inputRadius from previous log-response. 
    CIFilter *vignette = [CIFilter filterWithName:@"CIVignette"]; 
    [vignette setDefaults]; 
    [vignette setValue: image forKey: @"inputImage"]; 
    [vignette setValue: [NSNumber numberWithFloat: 5.0] forKey: @"inputIntensity"]; 
    [vignette setValue: [NSNumber numberWithFloat: 30.0] forKey: @"inputRadius"]; 

    // Attach the CIImage to CGImageRef and attach it as UIImage 
    CIImage *result = [vignette valueForKey: @"outputImage"]; 
    CGImageRef cgImageRef = [imageContext createCGImage:result fromRect:[result extent]]; 
    UIImage *targetImage = [UIImage imageWithCGImage:cgImageRef]; 

    // Attach UIImage to UIImageView in self.view, also position it, just for fun. 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:targetImage]; 
    [self.view addSubview:imageView]; 
    [imageView setImage:targetImage]; 
    imageView.frame = CGRectMake(0.0, 10.0, imageView.frame.size.width, imageView.frame.size.height); 

    // Release CGImageRef we created earlier. 
    CGImageRelease(cgImageRef); 
}
+0

마지막으로 CIVignette 내 고통을 종식하기위한 간단하게 당신을 투표 : 여기

내가 이전의 정보에서 CIVingette 함께있어 예입니다. 왜 속성은 최대 강도가 ​​1이고 최대 반경이 2라고 말합니까 ?? !!! 나는 다른 번호를 시도해야했다. – Meroon

관련 문제