我將UIImage
保存到Library目錄,但這需要更多的內存來保存圖像我編寫此代碼以保存圖像。UIImage保存到文檔目錄的內存使用率低
int i;
for(i = 0; i<[_selectedAssetArray count]; i++)
{
NSError *error;
NSString *documentsDirectory = [NSHomeDirectory()
stringByAppendingPathComponent:@"Library/VideoMaker"];
if (![[NSFileManager defaultManager] fileExistsAtPath:documentsDirectory])
[[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory withIntermediateDirectories:NO attributes:nil error:&error];
UIImage *image=[_selectedAssetArray objectAtIndex:i];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0f);
[imageData writeToFile:[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"Di%d.%@",i, @"png"]] atomically:YES];
}i++;
在這段代碼_selectedAssetArray是我UIImage
Array包含超過50個OR100圖像。 當我保存圖像的內存從20 MB增加到200或更多。所以我的應用程序終止,由於內存的壓力...
您可以檢查此鏈接... http://stackoverflow.com/questions/25324990/how-to-save-nsmutable-array-image-into-plist-or-document-folder-multiple-images – 2014-09-27 13:06:45