0

我尝试将 UIImagePicker 与编辑图像一起使用,代码运行良好,但不允许编辑,这是我的代码:

myFile.h

@interface MyCameraPickerController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {

    UIImageView * imageView;
    UIButton * choosePhotoBtn;
    UIButton * takePhotoBtn;
}

@property (nonatomic, strong) IBOutlet UIImageView * imageView;
@property (nonatomic, strong) IBOutlet UIButton * choosePhotoBtn;
@property (nonatomic, strong) IBOutlet UIButton * takePhotoBtn;

-(IBAction) getPhoto:(id) sender;

现在myFile.m调用所有函数:

@synthesize imageView,choosePhotoBtn, takePhotoBtn;

-(IBAction) getPhoto:(id) sender {

    UIImagePickerController * picker = [[UIImagePickerController alloc] init];

    picker.delegate = self;

    if((UIButton *) sender == choosePhotoBtn) {

        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    } else {

        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }

    [self presentViewController:picker animated:YES completion:nil];
}

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

    [info objectForKey:UIImagePickerControllerEditedImage];

    imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];

    [picker dismissViewControllerAnimated:YES completion:nil];
}

在此工作之后,我合并了两个图像并且在这里工作得很好,如果有人可以提供帮助的话,代码;):

- (IBAction)onSavePhoto:(id)sender{

    UIImage *bottomImage = self.imageView.image;//[UIImage imageNamed:@"bottom.png"]; //background image
    UIImage *image       = [UIImage imageNamed:@"overLay.png"]; //foreground image

    CGSize newSize = CGSizeMake(640, 640);
    UIGraphicsBeginImageContext( newSize );

    // Use existing opacity as is
    [bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

    // Apply supplied opacity if applicable
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:1.0];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
}

我看到我的图像,我可以拍一张照片,但我不能编辑这个,有人知道吗?谢谢。

4

1 回答 1

1

UIImagePickerController如果您想要的是允许编辑所选图像的内置功能,只需建立allowsEditing属性:

picker.allowsEditing = YES;

稍后您可以像这样检索它:

[info objectForKey:UIImagePickerControllerEditedImage];
于 2013-09-09T15:00:16.013 回答