PDA

View Full Version : How to give a name to a saved Image from the imagePickerController?




BarryK88
Apr 6, 2011, 05:09 AM
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

-(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:

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



robbieduncan
Apr 6, 2011, 11:13 AM
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".