将数组中的图像保存到filemanager中的文件

时间:2014-10-16 09:20:12

标签: objective-c nsfilemanager

我一直在使用nsfilemanager并尝试将图像保存为从数组中获取图像的文件。但我找不到解决方案。

1 个答案:

答案 0 :(得分:0)

要保存图像,您可以执行以下操作:

NSData *data = [NSData dataWithData:UIImageJPEGRepresentation(yourImage, 1.0f)];
[data writeToFile:theDesiredPath atomically:YES]);

因此,如果您想保存包含在数组中的图像,只需使用for语句迭代数组并调用这两行代码......

例如:

for (UIImage *img in arrayOfImages){
    NSData *data = [NSData dataWithData:UIImageJPEGRepresentation(img, 1.0f)];
    [data writeToFile:theDesiredPath atomically:YES]);
}