简体   繁体   English

如何有效地从iOS中的文档目录中读取多个图像

[英]How to efficiently read multiple images from documents directory in iOS

I am working on an app that saves multiple images in Documents directory. 我正在开发一个应用程序,可以在Documents目录中保存多个图像。 These images can be up to 100. Now use following method to read the image from Documents directory. 这些图像最多可以为100.现在使用以下方法从Documents目录中读取图像。 This method is called for all images in Documents directory. 为Documents目录中的所有图像调用此方法。

UIImage *currentImage = [UIImage imageWithContentsOfFile:pathOfFileInDocumentsDictory];

So in worse case this method will run for 100 images and I have checked using XCode that this method takes around 100 miliseconds. 因此,在更糟糕的情况下,此方法将运行100个图像,并且我已使用XCode检查此方法需要大约100毫秒。 So this makes 10 seconds for 100 images if I am not wrong. 因此,如果我没有错,这可以为100张图像制作10秒。 I want to make it efficient. 我想让它变得高效。 Is there any better way to read those image for efficiently and in less time? 有没有更好的方法来有效地在更短的时间内阅读这些图像?

Using run loops, you could do this: 使用运行循环,您可以这样做:

-(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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM