2013-02-24 56 views
0

我有一个名为obsPic1obsPic2didFinishPickingMediaWithInfo两个图像

两个影像的意见,他们收到来自拾取器/摄像机的图像。这适用于一个图像,但更多和图像是相同的。我如何为多个图像执行此操作?我曾尝试访问按钮发件人标签但获取未声明的标识符错误,我也尝试使用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]; 


} 
+0

我在上面的代码中没有看到任何对'obsPic2'的引用,您将图像添加到'obsPic2'的位置? – Shizam 2013-02-24 22:33:22

+0

代码调整,错过了复制和粘贴 – JSA986 2013-02-24 22:50:03

回答

1

无论您imageimage2参考相同的图像:

[info objectForKey:UIImagePickerControllerEditedImage]

你也许希望引用编辑和原始图像:

UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; 

UIImage *image2 = [info objectForKey:UIImagePickerControllerOriginalImage]; 

或反之亦然?如果OTOH您试图允许多个图像拾取ELCImagePickerController

+0

好吧,谢谢你,这是有道理的,为什么即时得到相同的图像,并没有两个引用是编辑图像。感谢您的链接,虽然在这种情况下它不适合我。我仍然需要找到获取不同图像到每个图像视图的方法 – JSA986 2013-02-24 23:42:50

+0

如果您想在每个视图中放置不同的图像,您必须让它们选择两次以获得两幅不同的图像。只要做一个'if'来检查你的'obsPic1'是否已经有一个图像,如果这样就填充'obsPic2'。如果你发现答案有帮助,即使它没有回答你100%:) – Shizam 2013-02-25 00:57:09