【问题标题】:Show images from documents directory in a image scroller在图像滚动条中显示文档目录中的图像
【发布时间】:2015-08-27 05:19:06
【问题描述】:

嘿,谁能帮帮我.. 我有一个复杂的问题。我在文档文件夹中有一组图像,每个图像的大小为 350 - 500 kb。我正在尝试在图像滚动器中显示这些图像,例如 iPhone 画廊的照片滚动器。我正在使用 UIPageViewController 通过滑动查看这些图像。

我的问题是关于显示图像。我尝试使用 SDWebImage 框架 (https://github.com/rs/SDWebImage) 来异步显示图像。但是在显示 2 个或更多图像后,它会显示内存警告并终止应用程序。我知道如何使用文件路径的 Url 从文件中检索数据。但是这些方法都不是内存高效的。像 contentsOfUrl 和 imageWithContentsOfFile 这样的方法会增加内存。所以任何人都建议这样做的好方法。提前致谢。

【问题讨论】:

  • 我没有看到你的代码!
  • 您忘记输入代码了。
  • 抱歉不知道如何在我的问题中包含代码

标签: ios objective-c image xcode6 nsdocumentdirectory


【解决方案1】:

要获取所有相同类型的图像,请使用以下方法查找。

-[NSBundle pathForResource:ofType:inDirectory:]

了解更多

- (NSString *)applicationDocumentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

}

-(void)loadimage{
NSString *workSpacePath=[[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"your image-name"];
UIImageView *myimage=[UIImageView alloc] initWithFrame:CGRectMake(0,0,20,20)];
myimage.image=[UIImage imageWithData:[NSData dataWithContentsOfFile:workSpacePath]];    
[self.view addSubView:myimage];
[myimage release];

}

【讨论】:

  • 这会导致更多的内存泄漏,因为它发生在主线程中。 ARC 也不允许发布。
猜你喜欢
  • 2013-02-24
  • 1970-01-01
  • 2014-08-19
  • 1970-01-01
  • 2012-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多