I know this question was asked by many people and there are several discussions and arguments on \"Why to use sqlite,use FMDB,core data\" etc.. to store or insert images in
For saving image to documents
- (void)saveImage:(UIImage *)image forPerson:(NSString *)fullName {
// Make file name first
NSString *filename = [fullName stringByAppendingString:@".png"]; // or .jpg
// Get the path of the app documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// Append the filename and get the full image path
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:filename];
// Now convert the image to PNG/JPEG and write it to the image path
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
// Here you save the savedImagePath to your DB
...
}
So, you later can get the image by
- (UIImage *)loadImage:(NSString *)filePath {
return [UIImage imageWithContentsOfFile:filePath];
}