NSData *imageData;
if (UIImagePNGRepresentation(imageToSave) == nil) {
imageData = UIImageJPEGRepresentation(imageToSave, 1);
} else {
imageData = UIImagePNGRepresentation(imageToSave);
}
NSString *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *filePath = [documentPath stringByAppendingPathComponent:@"a.png"];
[imageData writeToFile:filePath atomically:YES];
原文:http://www.cnblogs.com/yangmx/p/4110109.html