2014-09-12 2 views
-1

여기에 전체 만이 필터를 설립 모든 이미지가우시안 블러는 엑스 코드에 감동 지역에서만 필터 Apply (적용)

//Get a UIImage from the UIView 
UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

//Blur the UIImage 
CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage]; 
CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"]; 
[gaussianBlurFilter setValue:imageToBlur forKey:@"inputImage"]; 
[gaussianBlurFilter setValue:[NSNumber numberWithFloat:2] forKey:@"inputRadius"]; 
CIImage *resultImage = [gaussianBlurFilter valueForKey:@"outputImage"]; 
UIImage *endImage = [[UIImage alloc] initWithCIImage:resultImage]; 

//Place the UIImage in a UIImageView 
newView = [[UIImageView alloc] initWithFrame:self.view.bounds]; 
newView.image = endImage; 
[self.view addSubview:newView]; 
내가 흐림 이미지의 터치 영역에만 필터 적용됩니다 clases 검색 한

에 대한 가우시안 필터에 불과하다 영상. 이 같은

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ ... } 
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ ... } 
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ ... } 
+0

에 대해 동일한을 어쩌면 당신은 쓸 수 있습니다 내 질문은 CIFilter 단지에 적용 할 수 있도록하는 방법에 관한 것입니다 이러한 메소드의 코드는 무엇입니까? –

+0

이것이 가능한지 묻는 다면요. 아직 거기에 쓸 내용을 알아낼 수 없었습니다. – user3799263

답변

0

Juste는 작동합니다 :

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    //Get a UIImage from the UIView 
    UIGraphicsBeginImageContext(self.view.bounds.size); 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    //Blur the UIImage 
    CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage]; 
    CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"]; 
    [gaussianBlurFilter setValue:imageToBlur forKey:@"inputImage"]; 
    [gaussianBlurFilter setValue:[NSNumber numberWithFloat:2] forKey:@"inputRadius"]; 
    CIImage *resultImage = [gaussianBlurFilter valueForKey:@"outputImage"]; 
    UIImage *endImage = [[UIImage alloc] initWithCIImage:resultImage]; 

    //Place the UIImage in a UIImageView 
    newView = [[UIImageView alloc] initWithFrame:self.view.bounds]; 
    newView.image = endImage; 
    [self.view addSubview:newView]; 
} 

그리고 다른 방법 :

+0

아니요, 여기서 전체 이미지가 기본 이미지에 흐리게 추가됩니다. – user3799263

+0

아, 죄송합니다. 눌린 영역을 감지하고이 영역에 흐림 효과를 적용하고 싶습니까? –

+0

네, 그게 내가 찾고있는거야. Photoshop과 유사한 흐림 효과 도구입니다. – user3799263