ios - 如何从服务器获取多个图像并保存并在 iPhone 应用程序中显示它们?
<p><p>我正在使用以下代码获取单个图像。但是,如何处理多张图片呢?</p>
<p><em>这是我的代码:</em></p>
<pre><code>-(void)viewDidLoad
{
;
;
}
-(void)loadImageIntoMemory {
NSLog(@"Beginning download");
NSString *temp_Image_String = [ initWithFormat:@"http://www.thewavestore.com/appproductimage/"];
NSURL *url_For_Ad_Image = [ initWithString:temp_Image_String];
NSData *data_For_Ad_Image = [ initWithContentsOfURL:url_For_Ad_Image];
UIImage *temp_Ad_Image = [ initWithData:data_For_Ad_Image];
;
UIImageView *imageViewForAdImages = [ init];
imageViewForAdImages.frame = CGRectMake(0, 0, 320, 480);
imageView.image = ;
;
}
-(void)saveImage:(UIImage *)image {
NSLog(@"Saving");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = ;
NSString* path = ;
NSData* data = UIImagePNGRepresentation(image);
;
}
-(UIImage *)loadImage {
NSLog(@"Got the data!");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = ;
NSString* path = ;
UIImage* image = ;
return image;
}
</code></pre>
<p>请帮助解决这个问题,如果有任何好主意,请建议我。 </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>首先使用唯一名称保存您的图像(我使用当前时间)并将这些名称保存到数组中</p>
<pre><code>NSData *imageData = UIImagePNGRepresentation(chosenImage);
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = ;
NSDateFormatter *dateFormatter=[ init];
;
// save image with currentdate and time in the name
NSString * imageName = ]];
NSString *fullPathToFile = ;
//add all the images names to the imagepath array
;
//write image into file
;
</code></pre>
<p>然后从图像路径数组中检索图像</p>
<pre><code> for (NSString*path in imagePathArray ) {
NSArray *filepart = ;
NSString *filename = ;
NSString *extension = ;
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = ;
NSString *fileName = [NSString stringWithFormat:@"%@/%@",
documentsDirectory,path];
//NSString *filePath = [ pathForResource:filename ofType:extension];
NSData *fileData = ;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何从服务器获取多个图像并保存并在 iPhone 应用程序中显示它们?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33582365/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33582365/
</a>
</p>
页:
[1]