I have been working with nsfilemanager and trying to save images as files where the images are obtained from an array. But i couldn't find a solution.
Asked
Active
Viewed 423 times
-1
-
possible duplicate of [How to save UIImage to file with NSFileManager?](http://stackoverflow.com/questions/10094195/how-to-save-uiimage-to-file-with-nsfilemanager) – Jonathan F. Oct 16 '14 at 09:31
1 Answers
0
To save an image, you can do the following :
NSData *data = [NSData dataWithData:UIImageJPEGRepresentation(yourImage, 1.0f)];
[data writeToFile:theDesiredPath atomically:YES]);
So if you want to save the images contained into your array, simply iterate your array with a for statement and call theses two lines of code...
For example :
for (UIImage *img in arrayOfImages){
NSData *data = [NSData dataWithData:UIImageJPEGRepresentation(img, 1.0f)];
[data writeToFile:theDesiredPath atomically:YES]);
}

Jonathan F.
- 2,357
- 4
- 26
- 44
-
1ok. that one worked. and files are created. but when I try to retrieve those images to a imageview, nothing is showing up.-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { if ([flowernamearray count]!=0) { NSString *imagepath=[flowernamearray objectAtIndex:row]; UIImage *image; image=[UIImage imageWithContentsOfFile:imagepath]; imgvw.image=image; } } – user3815344 Oct 16 '14 at 09:55
-
This code seems correct. Try to set a breakpoint to see if `imgvw` is nil, check if `imagePath` is really a valid path. Otherwise, create another thread to explain precisely the problem you're encountering. – Jonathan F. Oct 16 '14 at 10:06