2016-04-14 94 views
3

我正在從攝像頭捕捉圖像替換圖像的一部分。我需要在我的應用程序中執行像這個應用程序一樣的活動。 https://itunes.apple.com/in/app/replace-my-face-funny-girls/id794033892?mt=8如何疊加相機捕捉圖像?

我需要一種方式,我怎樣才能從背景視圖與超級視圖圖像拍照,並保存合併的兩個圖像的新生成的圖像。 請建議我的解決方案。 簡單的工作,我沒有

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.picker = [[UIImagePickerController alloc] init]; 
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
self.picker.delegate = self; 
self.picker.allowsEditing = NO; 
self.picker.showsCameraControls = NO; 
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceFront; 

CGRect overlayRect = CGRectMake(0, 0, self.imageView.frame.size.width,self.imageView.frame.size.height); 

    UIView *overlayView = [[UIView alloc] initWithFrame:overlayRect]; 
UIImageView *capture_image=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.imageView.frame.size.width,self.imageView.frame.size.height)]; 

capture_image.image=[UIImage imageNamed:@"1.jpg"]; 
[overlayView addSubview:capture_image]; 
[self.picker setCameraOverlayView:overlayView]; 
[self.navigationController presentViewController:self.picker animated:YES completion:nil]; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 

UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; 
self.imageView.image = chosenImage; 
[picker dismissViewControllerAnimated:YES completion:NULL]; 
    } 
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 

[picker dismissViewControllerAnimated:YES completion:NULL]; 

} 

請還建議我,如果有任何存儲庫這樣工作方法。

回答

0

關於捕捉圖像:您可能想要查看FastttCamera,它允許您將攝像機視圖設置爲您定義的圖像視圖並相應地裁剪圖像。

祝你好運!

+0

無法打開./../Podfile.lock:沒有這樣的文件或目錄 diff:Manifest.lock:沒有這樣的文件或目錄錯誤: 沙盒與Podfile.lock不同步。運行'pod install'或更新你的CocoaPods安裝。 –

+0

這是一個不同的問題;-)。 你可以試着做'pod安裝'或明顯更新Cocoapods(或者如果你正在運行可能會導致問題的最新測試版,則降級Cocoapods),但是我恐怕不能幫你安裝pod安裝,因爲我我自己使用Swift併成功安裝它。 – Robski18

+0

是的,我解決了它,但它不是我想要的。我需要一個包含超級視圖中的圖像和背景視圖中的相機的視圖。 –

相關問題