Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-06-2011, 05:07 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 25
BarryK88 is on a distinguished road
Default How to give a name to a saved Image from the imagePickerController?

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
BarryK88 is offline   Reply With Quote
Old 04-06-2011, 10:27 AM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Save the image to your apps Documents folder and then load it from there. Or pass it between view controllers as an object (through properties, singleton class etc).
baja_yu is offline   Reply With Quote
Old 04-07-2011, 04:34 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 25
BarryK88 is on a distinguished road
Default

Thanks for your reply.

I fixed it by using:

Code:
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];		
    		NSString *pngFilePath = [NSString stringWithFormat:@"%@/foto1.png",docDir];
    		NSData *data = [NSData dataWithData:UIImagePNGRepresentation(image)];
    		
    		[data writeToFile:pngFilePath atomically:YES];
BarryK88 is offline   Reply With Quote
Reply

Bookmarks

Tags
imagenamed, save, uiimagepickercontroller, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 367
13 members and 354 guests
condor304, dansparrow, dre, ilmman, LezB44, michelle, Nobbsy, Objective Zero, samdanielblr, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:40 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0