gpt4 book ai didi

ios - UIImagePicker 不允许编辑图像

转载 作者:行者123 更新时间:2023-11-29 03:39:09 31 4
gpt4 key购买 nike

我尝试使用 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);
}

我看到了我的图像,我可以拍摄照片,但我无法编辑它,有人知道吗?谢谢。

最佳答案

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

picker.allowsEditing = YES;

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

[info objectForKey:UIImagePickerControllerEditedImage];

关于ios - UIImagePicker 不允许编辑图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18700815/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com