您好我是iPhone环境新手。我正在使用Xcode 4.5。我正在开发Camera Application。我想将图像从相机保存到文档目录中的单独文件夹以及照片库中的自定义相册中。我将图像保存到照片库中的自定义相册但我不知道如何保存它到文件目录......谁能告诉我怎么做...?
答案 0 :(得分:13)
尝试
UIImage *image = [UIImage imageNamed:@"Image.jpg"];
NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"New Folder"];
// New Folder is your folder name
NSError *error = nil;
if (![[NSFileManager defaultManager] fileExistsAtPath:stringPath])
[[NSFileManager defaultManager] createDirectoryAtPath:stringPath withIntermediateDirectories:NO attributes:nil error:&error];
NSString *fileName = [stringPath stringByAppendingFormat:@"/image.jpg"];
NSData *data = UIImageJPEGRepresentation(image, 1.0);
[data writeToFile:fileName atomically:YES];