gpt4 book ai didi

iphone - UIImagePickerControllerDelegate 返回空白 "editingInfo"字典对象

转载 作者:行者123 更新时间:2023-12-03 20:30:04 26 4
gpt4 key购买 nike

我有一个 iPhone 应用程序,它调用 UIImagePickerController 让人们可以选择通过相机或通过手机上的照片库选择图像。问题是,有时(不能总是让它复制。),本应由 didFinishPickingImage 委托(delegate)消息返回的 editorialInfo 字典对象返回空白或 (null)。其他人以前见过这个吗?

我正在 .h 文件中实现 UIImagePickerControllerDelegate,并且正确实现了两个委托(delegate)方法:didFinishPickingImage 和 imagePickerControllerDidCancel。

任何帮助将不胜感激。预先感谢您!

这是我的代码...

我的.h文件:

@interface AddPhotoController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
IBOutlet UIImageView *imageView;
IBOutlet UIButton *snapNewPictureButton;
IBOutlet UIButton *selectFromPhotoLibraryButton;
}
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UIButton *snapNewPictureButton;
@property (nonatomic, retain) UIButton * selectFromPhotoLibraryButton;

我的 .m 文件:

@implementation AddPhotoController
@synthesize imageView, snapNewPictureButton, selectFromPhotoLibraryButton;

- (IBAction)getCameraPicture:(id)sender
{

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsImageEditing = YES;

[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
NSLog(@"Image Meta Info.: %@",editingInfo);

UIImage *selectedImage = image;
imageView.image = selectedImage;
self._havePictureData = YES;
[self.useThisPhotoButton setEnabled:YES];

[picker dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}

最佳答案

我解决了这个问题。我在这里发布我的答案,希望它可以帮助处于类似情况的其他人:

1。已弃用的方法

UIImagePickerController 方法:

– imagePickerController:didFinishPickingImage:editingInfo:

在 iPhone OS v3.0 中已弃用。因此,即使我使用 SDK v2.2.1 构建应用程序,由于该应用程序将在 3.0 设备上运行,我需要使用新的改进方法:

- imagePickerController:didFinishPickingMediaWithInfo:editingInfo

2。关闭 ModalView

从库中选择图片或使用内置相机拍摄照片后,您必须做的第一件事是关闭选取器的模态视图窗口。之后,您可以执行任何图像处理例程。这是该方法的最终代码:

- (void) imagePickerController:(UIImagePickerController *)thePicker didFinishPickingMediaWithInfo:(NSDictionary *)imageInfo 
{
[thePicker dismissModalViewControllerAnimated:YES];
UIImage *img = [imageInfo objectForKey:@"UIImagePickerControllerEditedImage"];
previewImage.image = nil;
self.previewImage.image = img;

NSData *imageData = UIImagePNGRepresentation(img);
if ([imageData length] > 0) {

[self archivePictureData:imageData];
self._havePictureData = YES;

[self.useThisPhotoButton setEnabled:YES];
}

}

希望这对有需要的人有帮助。

谢谢

L.

关于iphone - UIImagePickerControllerDelegate 返回空白 "editingInfo"字典对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1325410/

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