Вы должны сохранить его в папке Documents
или Cache
.Вот как это сделать.
Сохранение в папку Documents
:
NSString* path = [NSHomeDirectory() stringByAppendingString:@"/Documents/myImage.png"];
BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path
contents:nil attributes:nil];
if (!ok)
{
NSLog(@"Error creating file %@", path);
}
else
{
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[myFileHandle writeData:UIImagePNGRepresentation(yourImage)];
[myFileHandle closeFile];
}
Загрузка из папки Documents
:
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
UIImage* loadedImage = [UIImage imageWithData:[myFileHandle readDataToEndOfFile]];
Вы также можете использовать UIImageJPEGRepresentation
, чтобы сохранить UIImage
как JPEG
файл.Более того, если вы хотите сохранить его в каталоге Cache
, используйте:
[NSHomeDirectory() stringByAppendingString:@"/Library/Caches/"]