[英]How to efficiently read multiple images from documents directory in iOS
我正在开发一个应用程序,可以在Documents目录中保存多个图像。 这些图像最多可以为100.现在使用以下方法从Documents目录中读取图像。 为Documents目录中的所有图像调用此方法。
UIImage *currentImage = [UIImage imageWithContentsOfFile:pathOfFileInDocumentsDictory];
因此,在更糟糕的情况下,此方法将运行100个图像,并且我已使用XCode检查此方法需要大约100毫秒。 因此,如果我没有错,这可以为100张图像制作10秒。 我想让它变得高效。 有没有更好的方法来有效地在更短的时间内阅读这些图像?
使用运行循环,您可以这样做:
-(void) loadInBackground {
[self performSelectorInBackground:@selector(_loadInBackground) withObject:nil];
}
-(void) _loadInBackground {
// Do all your heavy loading here
UIImage *currentImage = [UIImage imageWithContentsOfFile:pathOfFileInDocumentsDictory];
[self performSelectorOnMainThread:@selector(loadedImage:) withObject:currentImage waitUntilDone:YES];
}
-(void) loadedImage:(UIImage*)img {
// Do something with the loaded image
anImageView.image = img;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.