2015-03-19 97 views
1

我有兩個imageview。我怎樣才能合併這個圖像,使它看起來像一個單一的圖像。我嘗試了很多,像在第一張圖像的結尾處和第二張圖像的開頭處創建模糊和漸​​變,即使沒有像下面的圖像那樣得到所需的結果。如何合併兩個圖像從邊緣看起來像在iOS的單個圖像?

這是正常的圖像。

enter image description here

這個合併之後。

enter image description here

如何實現這樣的結果?請幫幫我。 在此先感謝。

+0

兩個圖像必須在邊緣上被模糊。圖像應該重疊。其中一個圖像應該在重疊區域上有alpha梯度。 – kelin 2015-03-19 12:17:47

回答

1

我得到了答案。使用下面的代碼並將漸變蒙版添加到邊界的兩個圖像中。您可以將第二個圖像視圖框的某個像素上移到第一個圖像,因此第一個圖像視圖邊框和第二個圖像視圖邊框將完全合併。

-(void)addGradientTo:(UIImageView*)imageView { 

CAGradientLayer *gradient = [CAGradientLayer layer]; 
gradient.frame = imageView.bounds; 

gradient.colors = [NSArray arrayWithObjects: 
          (id)[[UIColor colorWithWhite:0 alpha:0.2] CGColor], 
          (id)[[UIColor colorWithWhite:0 alpha:1] CGColor], 
          (id)[[UIColor colorWithWhite:0 alpha:1] CGColor], 
          (id)[[UIColor colorWithWhite:0 alpha:0.2] CGColor], nil]; 

gradient.locations = [NSArray arrayWithObjects: 
         [NSNumber numberWithFloat:0], 
         [NSNumber numberWithFloat:.1], 
         [NSNumber numberWithFloat:.9], 
         [NSNumber numberWithFloat:1], nil]; 

gradient.startPoint = CGPointMake(0,0.3); 
gradient.endPoint=CGPointMake(1,0.3); 
[imageView.layer setMask:gradient]; 

}

+0

你能告訴我你是如何合併這兩個圖像嗎? – 2017-07-21 10:25:27

相關問題