【发布时间】:2012-02-09 06:23:15
【问题描述】:
是否可以从我的应用程序下载图像并将其存储在 iPhone 内存中?我的应用程序中有各种大小的图像(url)。如何从我的应用下载并将其存储在图库中?
【问题讨论】:
标签: iphone objective-c ios xcode ipad
是否可以从我的应用程序下载图像并将其存储在 iPhone 内存中?我的应用程序中有各种大小的图像(url)。如何从我的应用下载并将其存储在图库中?
【问题讨论】:
标签: iphone objective-c ios xcode ipad
这会将图像保存到图库
UIImageWriteToSavedPhotosAlbum(yourImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void*)contextInfo
{
if (error != NULL)
{
// handle error
}
else
{
// handle ok status
}
}
更多信息 - 开发者文档页面 - https://developer.apple.com/library/ios/#documentation/uikit/reference/UIKitFunctionReference/Reference/reference.html
如何下载并存储到图库中:
UIImageWriteToSavedPhotosAlbum([UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"your_image_address.com"]]], self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
【讨论】:
试试这个教程。它显示了如何下载图像并存储到本地内存http://sugartin.info/2012/01/10/permanently-download-image-and-fetch-locally-images/
【讨论】: