UIImagePickerControllerDelegate 返回空白“editingInfo”字典对象

发布于 2024-08-02 07:56:28 字数 1807 浏览 2 评论 0原文

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

我正在 .h 文件中实现 UIImagePickerControllerDelegate,并且正确实现了两个委托方法: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];
}

I have an iPhone app that calls upon the UIImagePickerController to offer folks a choice between selecting images via the camera or via their photo library on the phone. The problem is that sometimes, (Can't always get it to replicate.), the editingInfo dictionary object that is supposed to be returned by didFinishPickingImage delegate message, comes back blank or (null). Has anyone else seen this before?

I am implementing the UIImagePickerControllerDelegate in my .h file and I am correctly implementing the two delegate methods: didFinishPickingImage and imagePickerControllerDidCancel.

Any help would be greatly appreciated. Thank you in advance!

Here is my code...

my .h file:

@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;

my .m file:

@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];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慵挽 2024-08-09 07:56:28

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

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。

I solved the problem. I'm posting my answer here in the hopes it helps someone else in a similar situation:

1. Deprecated Method

The UIImagePickerController method:

– imagePickerController:didFinishPickingImage:editingInfo:

is deprecated in v3.0 of the iPhone OS. So even though I built the app using the SDK v2.2.1, because the app will be running on 3.0 devices, I needed to use the new and improved method:

- imagePickerController:didFinishPickingMediaWithInfo:editingInfo

2. Dismissing the ModalView

The first thing you must do after you have selected a picture from the library or taken a picture with the built-in camera, is to dismiss the picker's modal view window. After that, you can perform any image processing routines. Here is what my final code looks like for that method:

- (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];   
  }

}

I hope this helps someone who needs it.

Thanks,

L.

允世 2024-08-09 07:56:28

我得到了它 !

我不知道为什么,但我在 appDelegate 中注释了一行:
“[window makeKeyAndVisible]”

我只是将其分解并再次构建。现在ImagePicker的Edit功能运行了。

我希望这有帮助。

卢库鲁

I GOT IT !

I don't know why, but I had comment a line in my appDelegate :
"[window makeKeyAndVisible]"

I just decomment It and build again. So the Edit function of ImagePicker run now.

I hope this help.

Lkuulu

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文