1
我的照片編輯應用程序的工作,我必須合併兩個圖像一個在另一個這樣。核心圖像過濾器CISourceOverCompositing不能正常工作
我已經實現了以下代碼這樣做:
這裏IMGEDIT是背景圖像和
IMGEDIT是含有的UIImageView IMGEDIT。
UIImage *tempImg = [UIImage imageNamed:[NSString stringWithFormat:@"borderImg"]];
CIImage *inputBackgroundImage = [[CIImage alloc] initWithImage:imgedit];
CIImage *inputImage = [[CIImage alloc]initWithImage:tempImg] ;
CIFilter *filter = [CIFilter filterWithName:@"CISourceOverCompositing"];
[filter setDefaults];
[filter setValue:inputImage forKey:@"inputImage"];
[filter setValue:inputBackgroundImage forKey:@"inputBackgroundImage"];
CIImage *outputImage1 = [filter valueForKey:@"outputImage"];
CIContext *context = [CIContext contextWithOptions:nil];
imgEdit.image = [UIImage imageWithCGImage:[context createCGImage:outputImage1 fromRect:outputImage1.extent]];
但outputImage我在執行上面的代碼後得到的是:
我還試圖調整輸入白框圖像,通過使用以下代碼:
tempImg=[tempImg resizedImageToSize:CGSizeMake(imgEdit.image.size.width,imgEdit.image.size.height)];
通過使用上面的代碼圖像得到適當的調整,但但是,這也不能正常工作。
請幫我從這裏出去。
您的寶貴幫助將不勝感激。
提前謝謝。
背景圖像是矩形的肖像和你的面具形象是正方形..其實什麼是你想要從圖像達到的效果?或者我錯過了什麼? –
它看起來像'CIContext'調整自身的大圖像大小。用你的蒙版圖像的大小繪製你的背景。參考在'CIContext'中使用'drawImage:inRect:fromRect:'方法。我對濾波器不太瞭解。很高興知道你是否也有問題。 –
其實我想在背景圖像上添加上面顯示的白色框。問題是當背景圖像是方形框架,那麼它很好,我可以得到我想要的輸出。但是當它是矩形框架時會出現問題。 很多感謝您的快速回復。 –