我尝试将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);
}
我看到了我的形象,我可以拍摄一张照片,但是我无法编辑这个,有人有想法吗?感谢。
答案 0 :(得分:1)
如果你想要的是内置UIImagePickerController
以允许编辑所选图像,只需建立allowsEditing
属性:
picker.allowsEditing = YES;
之后您可以像这样检索它:
[info objectForKey:UIImagePickerControllerEditedImage];