Reputation: 55
(sorry for my english)
I need save an image in the application path and after load the image on ImageView.
To get the application path:
NSString * imagePath = NSHomeDirectory();
imagePath = [imagePath stringByAppendingPathComponent:@"/image.png"];
After, to save the image:
NSData *imageData = UIImagePNGRepresentation(self.imageView.image);
[imageData writeToFile:self.imagePath atomically:YES]
To load the image saved on app path
self.imageSaved.image = [UIImage imageWithContentsOfFile:self.imagePath];
The problem is that the image wasn´t save into the path
Regards
Edit:
Problem solved, only i need change the path for file
[imagePath stringByAppendingPathComponent:@"Documents/image.png"];
Thanks for your answers.
Upvotes: 2
Views: 1627
Reputation: 8449
NSString *imagePath = NSHomeDirectory();
imagePath = [imagePath stringByAppendingPathComponent:@"/Documents/image.png"];
or
imagePath = [imagePath stringByAppendingPathComponent:@"/Library/image.png"];
Upvotes: 2
Reputation: 33421
You can't save there on iOS applications. You can only save into your documents directory.
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
EDIT I guess what I should say is you SHOULD only save files to the documents directory if they are files like the one you are creating in your example.
Upvotes: 1