简体   繁体   English

从UIImagePicker到NSMutableArray的图像

[英]Image from UIImagePicker to NSMutableArray

Very simply, I want to take a photo using UIImagePicker and place it into an NSMutableArray . 很简单,我想使用UIImagePicker拍摄照片并将其放入NSMutableArray I hve the following code below. 我在下面的代码如下。 The camera part works fine and for test purposes the image is displayed in a UIImage called photoImageView . 相机部件工作正常,出于测试目的,图像显示在名为photoImageViewUIImage However I can't seem to add the image into the array. 但是我似乎无法将图像添加到数组中。 Any help gratefully received. 任何帮助感激不尽。

@property (nonatomic, retain) NSMutableArray *photos;

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *photoTaken = (UIImage *)[info valueForKey:UIImagePickerControllerOriginalImage];
photoImageView.image=photoTaken;
[photos addObject:[UIImage photoTaken];
[picker dismissViewControllerAnimated:YES completion:nil];
}

Have you instantiated the array somewhere ( viewDidLoad for example): 你有没有在某个地方实例化数组(例如viewDidLoad ):

self.photos = [NSMutableArray alloc] init];

?

1)Are you initialising the photos NSMutableArray? 1)你是否正在初始化照片NSMutableArray? Sometimes addObject: won't throw an error when trying to insert an object into a NULL NSArray. 有时addObject:在尝试将对象插入NULL NSArray时不会抛出错误。

2) 2)

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *photoTaken = (UIImage *)[info valueForKey:UIImagePickerControllerOriginalImage];
    if (photoTaken)
    {
        photoImageView.image=photoTaken;
        [photos addObject:photoTaken];
    }else{
        NSLog(@"Selected photo is NULL");
    }
    [picker dismissViewControllerAnimated:YES completion:nil];
}

添加到(Ian L)后修改如下

     [photos addObject: photoTaken];

photoTaken is already instantiated as an UIImage object. photoTaken已经实例化为UIImage对象。 No need to do : 无需做:

[photos addObject : [UIImage photoTaken]];

Simply do this : 只需这样做:

[photos addObject : photoTaken];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM