Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

XcodeNewb

macrumors member
Original poster
Feb 6, 2009
79
0
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
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.