I have an iPhone application using a UIImagePickerController. As sourceType I have
UIImagePickerControllerSourceTypePhotoLibrary
UIImagePickerControllerSourceTypeCamera
UIImagePickerControllerSourceTypeSavedPhotosAlbum
so the user can make a photo or select one from the photo library from the photos or camera photos.
The image will be displayed in a UIImageView. The image should be saved if the user closes the app. So for text fields, I use NSUserDefaults. I know, it is not a good way to save the image inside the NSUSerDefaults with NSData, so I want to save / copy the image to a folder which is controlled by my application similar to the NSUserDefaults.
How can I do this? I want to save it, and then I can write the path to the file into my NSUserDefaultsand read it on startup of the application.
// Write a UIImage to JPEG with minimum compression (best quality) // The value 'image' must be a UIImage object // The value '1.0' represents image compression quality as value from 0.0 to 1.0 [UIImageJPEGRepresentation(image,1.0) writeToFile:jpgPath atomically:YES];
// Write image to PNG [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
// Let's check to see if files were successfully written...
// Point to Document directory NSString*documentsDirectory =[NSHomeDirectory(); stringByAppendingPathComponent:@"Documents"];
// Write out the contents of home directory to console NSLog(@"Documents directory: %@",[fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
iPhone - UIImagePickerController -> save the image to app folder
http://stackoverflow.com/questions/4957972/iphone-uiimagepickercontroller-save-the-image-to-app-folder 4down votefavoriteHello!I have an iPhone application using a U