0

我正在开发一个使用相机的应用程序。我正在使用浏览选项来浏览图库中的照片。如果需要,我还提供了拍照的选项。为了在浏览时获取所选照片,我实现了 UIImagePickerControllerDelegate 方法:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo 
 {
      [self dismissModalViewControllerAnimated:YES];
      imageView.image = img;    
  }

我正在用这种方法获取选定的图像。但是如何在我的 imageView 中获取相机捕获的图像而不将其保存到图库中?我会用同样的方法得到图像吗?

4

3 回答 3

2

您正在使用imagePickerController:didFinishPickingImage:editingInfo:. 这在 ios 3.0 中已弃用。参考UIImagePickerControllerDelegate也参考这个链接为什么不使用不推荐使用的方法。

你必须使用imagePickerController:didFinishPickingMediaWithInfo:如下:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{
     yourImageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
     [self dismissModalViewControllerAnimated:YES];
}

这适用于您的相机和照片库。您也不需要保存使用相机拍摄的图像。您可以像此代码一样直接将其分配给您的图像视图。

希望这对您有所帮助。

于 2012-08-07T06:04:52.050 回答
1

这很简单,您只需将UIImage直接传递到您的UIImageView

 yourImageView.image = img;
于 2012-08-07T05:53:58.737 回答
0

请试试这个:

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSLog(@"Media Info: %@", info);
NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
    UIImage *photoTaken = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    //Save Photo to library only if it wasnt already saved i.e. its just been taken
    if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
        yourImageView.image = img }
}
[self dismissModalViewControllerAnimated:YES];
}
于 2012-08-07T06:01:06.720 回答