2016-10-14 7 views
0

이야기는 사용자가 선 또는 곡선을 그려서 이미지의 일부를 선택한다는 것입니다. 선택에 따라 가장자리 감지기를 사용하여 마스크가 만들어집니다.이미지의 일부를 선택하여 모서리 감지가있는 마스크 만들기

어떻게하면됩니까?
CoreImage와 GPUImage가이를 가능하게 할 수 있습니까?
마스크를 만들기에 가장자리 감지가 충분합니까?

이미지 처리 및 조작에 대한 고급 지식이 없습니다. 나는 그것을 이해하고 배우려는 시작일 뿐이다. 그건 그렇고, 이것은 iOS에서 이루어져야합니다.

this1 (마스킹 부분)과 동일합니다.

답변

0

마스크를 사용하여 이미지의 일부를 선택하는 방법을 보여 준 샘플을 작성했습니다. 더 복잡한 효과를 구현하려면 경로를 변경해야하며 원하는 모양을 얻을 수 있습니다.

@interface MainViewController() 

@property UIImageView* imageV; 
@property UIView* selectView; 
@property UIView *blockView; 
@property CGPoint startPoint; 
@property CGPoint endPoint; 

@end 

@implementation MainViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    UIBarButtonItem *recoverItem = [[UIBarButtonItem alloc] initWithTitle:@"Recover" style:UIBarButtonItemStyleDone target:self action:@selector(recover)]; 
    [self.navigationItem setLeftBarButtonItem:recoverItem]; 

    _imageV = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
    _imageV.image = [UIImage imageNamed:@"test"]; 
    [self.view addSubview:_imageV]; 

    _blockView = [[UIView alloc] init]; 
    _blockView.frame = _imageV.bounds; 
    _blockView.backgroundColor = [UIColor whiteColor]; 
    [_imageV addSubview:_blockView]; 
    _blockView.hidden = true; 

    _selectView = [[UIView alloc] init]; 
    _selectView.layer.borderColor = [UIColor greenColor].CGColor; 
    _selectView.layer.borderWidth = 2; 
    [_imageV addSubview:_selectView]; 
    _selectView.hidden = true; 

    UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; 
    [self.view addGestureRecognizer:panGR]; 
} 

- (void) handlePan: (UIPanGestureRecognizer *)pan{ 
    if (UIGestureRecognizerStateBegan == pan.state) { 
     _startPoint = [pan locationInView:_imageV]; 
    } 
    else if (UIGestureRecognizerStateChanged == pan.state) { 
     _selectView.hidden = false; 
     CGPoint currentP = [pan locationInView:_imageV]; 
     float rectWidth = currentP.x - _startPoint.x; 
     float rectHeight = currentP.y - _startPoint.y; 
     _selectView.frame = CGRectMake(_startPoint.x, _startPoint.y, rectWidth,rectHeight); 
    } 
    else if (UIGestureRecognizerStateEnded == pan.state) { 
     _endPoint = [pan locationInView:_imageV]; 
     float rectWidth = _endPoint.x - _startPoint.x; 
     float rectHeight = _endPoint.y - _startPoint.y; 
     //create path 
     UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:[UIScreen mainScreen].bounds]; 
     UIBezierPath *otherPath = [[UIBezierPath bezierPathWithRect:CGRectMake(_startPoint.x, _startPoint.y, rectWidth,rectHeight)] bezierPathByReversingPath]; 
     [maskPath appendPath:otherPath]; 
     //set mask 
     CAShapeLayer *maskLayer = [CAShapeLayer layer]; 
     maskLayer.path = maskPath.CGPath; 
     [_blockView.layer setMask:maskLayer]; 
     _blockView.hidden = false; 

     _selectView.hidden = true; 
    } 
} 

-(void) recover{ 
    _blockView.hidden = true; 
} 

@end 

희망이 있으면 도움이 될 것입니다.

+0

매우 감사드립니다. 이는 관심 영역을 정의하는 데 도움이됩니다. 내 문제는 투자 수익 (ROI) 뒤에 있으며 맞춤 필터를 만드는 것 같습니다. – mownier