How to give a name to a saved Image from the imagePickerController?

Discussion in 'iPhone/iPad Programming' started by BarryK88, Apr 6, 2011.

  1. macrumors member

    Joined:
    Mar 1, 2011
    #1
    I'm using an imagePickerController to replace my existing images inside my view. The function works within the same IB-file. However I'd like to load the chosen image in another IB-File as well. I think that the solution is to give a name to the image when saved. After it is saved I'd like to call the image (by name) from my memory within my other IB-file.

    Here's a snippit of code I'm using within the photopicker IB-file

    Code:
    -(IBAction)setPhoto{
    
        image1.image = fotoView.image;
    }
    
    -(IBAction)getCameraPicture:(id)sender
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsImageEditing = YES;
        picker.sourceType = (sender == takePictureButton) ? UIImagePickerControllerSourceTypeCamera :
        UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        [self presentModalViewController: picker animated:YES];
        [picker release];
    }
    
    -(IBAction)selectExitingPicture
    {
        if([UIImagePickerController isSourceTypeAvailable:
            UIImagePickerControllerSourceTypePhotoLibrary])
        {
            UIImagePickerController *picker= [[UIImagePickerController alloc]init];
            picker.delegate = self;
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self presentModalViewController:picker animated:YES];
            [picker release];
        }
    }
    
    -(void)imagePickerController:(UIImagePickerController *)picker
          didFinishPickingImage : (UIImage *)image
                     editingInfo:(NSDictionary *)editingInfo
    {
        [picker dismissModalViewControllerAnimated:YES];
    
        fotoView.image = image;
    
        NSData* imdata =  UIImagePNGRepresentation ( image );
        UIImage* im8 = [UIImage imageWithData:imdata];
        UIImageWriteToSavedPhotosAlbum(im8, nil, nil, nil);
    }
    
    -(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
    {
        [picker dismissModalViewControllerAnimated:YES];
    }
    within my other class I'd like to call this image by means of:

    Code:
    if (#some condition){
            UIImage *img = [UIImage imageNamed:@"Name of the image.png"];
            [image1 setImage:img];
    
    }
    How will I be able to give a name to the saved image and call it afterwords within another class?

    Help is greatly appreciated
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Image named can only be used to load images from your own applications bundle. The "name" is the file name. As you are saving to the photos album you cannot retrieve the image by "name".
     

Share This Page