0

我已经UITableView从 URL 加载了图像。现在如何将这些图像保存在我的iPhone中。

下载图像时,使用适当的命名约定创建它的缩略图并保存。

请为此保存图像提供一些提示或方法

4

3 回答 3

2
NSURL *url = [[NSURL alloc] initWithString:@"http://image.com"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:data];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

有关UIImageWriteToSavedPhotosAlbum 的更多信息,您可以在此处找到

于 2012-09-11T07:32:05.753 回答
0
// data is the NSData you obtained
// from the NSURLConnection

UIImage* image = [[UIImage alloc] initWithData:data];

// path is an NSString containing the path
// to save the file, usually inside Documents, Cache, etc,

[image writeToFile:path];

*阅读 Apple 的文档,了解如何获取相关目录的路径。

于 2012-07-14T10:52:32.213 回答
0

这是从图像的 weburl 下载图像并将其保存在应用程序中的代码。

NSURLRequest *request = [NSURLRequest requestWithURL:imageURL];
 [NSURLConnection connectionWithRequest:request delegate:self];

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];
 NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"image.jpg"];
 NSData *thedata = [NSData dataWithContentsOfURL:imageURL];
 [thedata writeToFile:localFilePath atomically:YES];
于 2012-07-14T11:07:49.953 回答