0

我有两个名为obsPic1obsPic2

他们从选择器/相机接收图像。这适用于一个图像,但任何更多图像都是相同的。我如何为多个图像执行此操作?我试过访问按钮发件人标签但得到未声明的标识符错误,我也尝试过使用if语句。这样做的正确方法是什么?

- (IBAction)addObsPhotoBtnPresssed:(id)sender {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        LogCmd();
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.delegate = self;
        imagePicker.allowsEditing = YES;
        [self.editController presentModalViewController:imagePicker animated:YES];
        //iPad
    }
    else {
        if (self.pop) {
            [self.pop dismissPopoverAnimated:YES];
        }
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePickerController.delegate = self;
        imagePickerController.allowsEditing = YES;
        self.pop=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
        [self.pop presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    }
}


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

    [picker dismissModalViewControllerAnimated:YES];
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    self.obsPic1.backgroundColor = [UIColor whiteColor];
    self.obsPic1.image = image;
    NSData *imageData = UIImagePNGRepresentation(image);
    NSString *path = [ICUtils pathForDocument:@"obsPic.png"];
    [imageData writeToFile:path atomically:NO];


    UIImage *image2 = [info objectForKey:UIImagePickerControllerEditedImage];
    self.obsPic2.backgroundColor = [UIColor whiteColor];
    self.obsPic2.image = image2;
    NSData *imageData2 = UIImagePNGRepresentation(image);
    NSString *path2 = [ICUtils pathForDocument:@"obsPic2.png"];
    [imageData2 writeToFile:path2 atomically:NO];


}
4

1 回答 1

1

imageimage2引用相同的图像:

[info objectForKey:UIImagePickerControllerEditedImage]

您是否希望参考已编辑和原始图像:

    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];

    UIImage *image2 = [info objectForKey:UIImagePickerControllerOriginalImage];

或相反亦然?如果 OTOH 你试图允许多个图像选择查看ELCImagePickerController

于 2013-02-24T23:11:39.877 回答