Sharath Babu
Sharath Babu

Reputation: 71

Save images in a n ios app

I am creating a greeting card app.I have some existing templates and i also can create new greeting cards by adding cliparts ,textstyles etc.I have saved the image as a uiimage object.I am stuck at the point to save these images for future use.Please help.

Upvotes: 2

Views: 2757

Answers (2)

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

To save a UIImage to file do the following

NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/img.jpg"];

//Save
NSData* imageData = UIImageJPEGRepresentation(img, 1.0);
[imageData writeToFile:path atomically:YES];

//Load
NSData* imageData = [NSData dataWithContentsOfFile:path];
UIImage *image = [UIImage imageWithData:imageData];

Upvotes: 2

iNeal
iNeal

Reputation: 1729

Check out this link. How to save picture to iPhone photo library?

You can also save the image in iPhone file system by converting image to data and save data to file.

NSData *data = UIImagePNGRepresentation(yourImage);
[data writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile]

Upvotes: 0

Related Questions