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

时间:2009-08-25 00:08:08

标签: iphone uiimagepickercontroller

我有一个iPhone应用程序,它调用UIImagePickerController,让人们可以选择通过相机选择图像还是通过手机上的照片库。问题是有时,(不能总是让它复制。),应该由didFinishPickingImage委托消息返回的editingInfo字典对象,返回空白或(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];
}

2 个答案:

答案 0 :(得分:6)

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

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,

答案 1 :(得分:0)

我知道了!

我不知道为什么,但我在appDelegate中评论过一行: “[window makeKeyAndVisible]”

我只是退缩并再次构建。所以ImagePicker的Edit函数现在运行。

我希望这有帮助。

Lkuulu