我目前正在製作iphone應用程序,用戶拍攝照片或從相冊中選擇照片,然後在圖像上放置覆蓋圖。用戶可以縮放,旋轉和保存圖像。目前,我可以拍照,或選擇一張專輯。至於疊加層,我只是使用UIImageView並將其放置在「接口」構建器中的層次結構頂部。對於相機,我正在使用此代碼:拍照後編輯圖像
-(IBAction)getPhoto:(id)sender {
// Create an image picker controller
UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
if((UIButton *) sender == choosePhotoBtn) {
// Set source to photo albums
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
else {
// Set source to camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
}
// Delegate is self
imagePicker.delegate = self;
// Allow editing of image
imagePicker.allowsEditing = YES;
// Show image picker
[self presentModalViewController:imagePicker animated: YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Dismiss modalviewcontroller
[picker dismissModalViewControllerAnimated:YES];
// Displaying image to the imageView
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Access the uncropped image from info dictionary
UIImage * image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Save Image
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
[picker release];
}
我現在遇到的問題是在照片拍攝後編輯照片。如何自定義相機這樣的表現?:
選擇或者使用相機或正從專輯
一旦選定照片,覆蓋圖像將變爲一個在那裏我」我在臉上放了一個「圓圈」,照片就像面具一樣在下面。這個視圖也可以全屏編輯。你可以旋轉,縮放和移動圖像,直到你點擊完成。
我已閱讀手冊中的這一部分,但似乎無法理解如何使用它。 http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
希望有人能指出我正確的方向。
非常感謝。 -Hakimo
其中OP使用UIImagePickerControllerOriginalImage或UIImagePickerControllerEditedImage?我不明白你。 – inherithandle 2015-10-06 12:19:51
@inherithandle OP是指UIImagePickerControllerDelegate的'imagePickerController:didFinishPickingMediaWithInfo:'方法。 'info'參數包含一個NSDictionary,其中包含編輯信息鍵,如「UIImagePickerControllerOriginalImage」和「UIImagePickerControllerEditedImage」 – 2016-01-20 11:15:42