简体   繁体   English

在图像滚动器中显示来自文档目录的图像

[英]Show images from documents directory in a image scroller

Hey can anybody help me.. I have a complex problem . 嘿,有人可以帮我吗。我有一个复杂的问题。 I have a set of images in the documents folder each with size of 350 - 500 kb. 我在documents文件夹中有一组图像,每个图像的大小为350-500 kb。 I am trying to display those images in a image scroller like the photoscroller of iPhone gallery. 我试图在像iPhone画廊的photocroller的图像滚动器中显示那些图像。 I am using UIPageViewController to view those images via sliding. 我正在使用UIPageViewController通过滑动查看那些图像。

My Problem is about showing images. 我的问题是关于显示图像。 I tried to use SDWebImage framework ( https://github.com/rs/SDWebImage ) to display image asynchronously. 我试图使用SDWebImage框架( https://github.com/rs/SDWebImage )异步显示图像。 But after 2 or more images displayed it shows memory warning and kills the app. 但是在显示2张或更多图片后,它会显示内存警告并杀死该应用程序。 I know how to retrieve data from file with Url of the file path.. But none of those methods are memory efficient. 我知道如何使用文件路径的Url从文件中检索数据。但是这些方法都不是内存有效的。 Methods like contentsOfUrl and imageWithContentsOfFile will rise the memory . 诸如contentsOfUrl和imageWithContentsOfFile之类的方法将增加内存。 So anyone suggest a goo way to do this. 因此,任何人都建议采取一种行之有效的方法。 Thanks in advance. 提前致谢。

For getting all images of same type use following method to find. 要获取所有相同类型的图像,请使用以下方法查找。

-[NSBundle pathForResource:ofType:inDirectory:]

For more 欲了解更多

- (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];

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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