微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

拍照后编辑图像

如何解决拍照后编辑图像

| 我目前正在制作一个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);

[picker release];
}
我现在遇到的问题是在拍摄照片后对其进行编辑。如何自定义相机以使其表现如下: 选择使用相机还是从相册中获取照片 选择后,叠加层图像将更改为我在脸部上加一个“圆圈”的图像,并且照片将像面罩一样位于下面。此视图还可以全屏编辑。您可以旋转,缩放和移动图像,直到单击完成。 我已经阅读了本手册的这一部分,但似乎无法理解如何使用它。 http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html 希望有人能指出我正确的方向。 非常感谢。 -H     

解决方法

        有一种方法可以减少您的代码太多:
- (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 \”,就这样!     ,        对于Q1,是否可以实施操作表,以便用户可以选择使用相册中的照片或拍摄新照片。操作表功能如下所示:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        picker = [[UIImagePickerController alloc]init];
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        picker.delegate = self;
        [self presentModalViewController:picker animated:YES];
        [picker release];
    }

    else if (buttonIndex == 1) {
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            picker = [[UIImagePickerController alloc]init];
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;
            picker.allowsEditing = YES;
            picker.delegate = self;
            [self presentModalViewController:picker animated:YES];
            [picker release];
        }
        else {
            UIAlertView *noCameraMsg = [[UIAlertView alloc] initWithTitle:@\"no camera on this phone\" message:@\"\" delegate:self cancelButtonTitle:@\"OK\" otherButtonTitles:nil];
            [noCameraMsg show];
            [noCameraMsg release];

        }


}
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。