finding photo library image path

Discussion in 'iOS Programming' started by XcodeNewb, Jun 3, 2009.

  1. XcodeNewb macrumors member

    Joined:
    Feb 6, 2009
    #1
    I have searched everywhere and cannot find a definite answer about this.

    When I pick an image form the photo library I would like to save it to a file and reload it the next time the user runs the app.

    How exactly can I get the image the user picked and save it somewhere to access later.

    I tried this but it dies not seem to save the image:

    Code:
    	NSString *newFilePath = [NSHomeDirectory() stringByAppendingPathComponent: @"ChosenPic.jpg"];
    	
    	NSData * imageData = UIImageJPEGRepresentation(image, 1.0);
    	//data = imageData;
    	if (imageData != nil) {
    		NSLog(@"HERE [%@]", newFilePath);
    		[imageData writeToFile:newFilePath atomically:YES];
    	}
    	
    	imageView.image =[UIImage imageNamed:newFilePath];
    
    Any ideas?

    Thanks
     
  2. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #2
    i'm pretty sure you can select and image from the camera roll and just save it's path to your app's user defaults.

    [EDIT] also, i don't think you can use NSHomeDirectory() with cocoa touch. apps are sandboxed with documents, library and tmp folders.
     

Share This Page