拍照后编辑图像 [英] Edit image after taking a picture
问题描述
我目前正在制作一款iphone应用程序,用户可以在其中拍摄照片或从相册中选择照片,然后在图像上方放置一个叠加层。然后,用户可以缩放,旋转和保存图像。目前,我可以拍照,或者为相册选择一张。至于叠加层,我只使用了UIImageView并将它放在Interface builder中的层次结构之上。对于相机,我正在使用此代码:
I'm currently making an iphone app where the user takes a photo or select it from an album, then an overlay is placed over the image. The user can then scale, rotate and save the image. Currently, I can take pictures, or choose one for the album. As for the overlay, I just used UIImageView and placed it on top of the hierarchy in Interface builder. For the camera, I'm using this code:
-(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];
}
我现在遇到的问题是编辑后的照片拍摄。如何自定义相机的行为?:
The problem I'm having right now, is editing the photo after it's being taken. How do I customise the camera to behave like this?:
-
选择使用相机或从相册中获取照片
Choose either use the camera or getting the photo from the album
一旦选择,叠加图像将变为我在脸部放置圆圈的图像,照片将像面具一样在下面。此视图也可以全屏编辑。您可以旋转,缩放和移动图像,直到您单击完成。
Once chosen, the overlay image will change to a one where I've put a "circle" in the face, and the photo will be underneath like a mask. This view will also be able to edit in full screen. You can rotate, scale and move the image until you click done.
我在手册中已阅读此部分但我似乎无法理解如何使用它。 http://developer.apple.com/library/ios/# documentation / UIKit / Reference / UIImagePickerController_Class / UIImagePickerController / UIImagePickerController.html
I've read this part in the manual but I can't seem to understand how to use it. http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
希望有人能指出我正确的方向。
Hope someone can point me to the right direction.
非常感谢。
-Hakimo
Thanks very much. -Hakimo
推荐答案
有一种方法不要改变你的代码:
there's a way don't change your code much:
- (IBAction)takePicture:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
} else {
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[imagePicker setAllowsEditing:YES];
[imagePicker setDelegate:self];
//place image picker on the screen
[self presentViewController:imagePicker animated:YES completion:nil];
}
如果要使用编辑后的图像,请更改UIImagePickerControllerOriginalImage到UIImagePickerControllerEditedImage,就是这样!
If you want to use the image that after editing, please change "UIImagePickerControllerOriginalImage" to "UIImagePickerControllerEditedImage", that's it!
这篇关于拍照后编辑图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!