加载iphone nsmutablearray图像库的最佳方法(600多项) [英] best way to load an image library of iphone nsmutablearray (600+ items)

查看:71
本文介绍了加载iphone nsmutablearray图像库的最佳方法(600多项)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含图像库的应用程序。我已经将图像导入到Xcode中的资源文件夹中,并且当应用程序加载时我正在将它们加载到appDelegate中的数组中。这种情况每次都在发生。我现在担心随着库的增长,应用程序将耗尽内存。有没有更好的方法加载这些?

I have created an app which has a library of images. I have imported the images in to my resources folder in Xcode and am currently loading them in to an array in the appDelegate when the app loads. This is happening each time. I am now worried that as the library grows the app will run out of memory. Is there a better way of loading these?

结构是

图书馆>类别>图像列表>图像

Library > category > image list > image

我有一个名为 mainLibrary 的NSMutableArray,然后我为每个类别添加另一个nsmutablearray。例如

I have an NSMutableArray called mainLibrary which I then add another nsmutablearray for each category. For example

NSMutableArray *arrHome = [[NSMutableArray alloc] initWithObjects:  @"Home",                           
    [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"%@/%@", resourcePath, @"alarm_clock.png"], @"image_path", @"Alarm Clock", @"title", nil],
    [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"%@/%@", resourcePath, @"bathtub.png"], @"image_path",@"Bathtub", @"title", nil],

    nil];
[mainLibrary addObject: arrHome];

以上是家庭类别,仅包含两张图片。对于其他类别,我为每个图像都有NSDictionary行 - 每个类别最多可以有100个图像。

The above is for the "home" category and contains only two images. For other categories, I have the NSDictionary line for each image - there can be up to 100 images in each category.

如果我将50mb +的图像加载到阵列中,这将导致应用程序无响应 - 或者更可能的是,因为它使用了更多的24mb而崩溃ish)每个app的津贴??

If I am loading in 50mb+ of images to an array will this cause the app to become unresponsive - or more than likely, simply crash as it uses more of the 24mb (ish) allowance per app??

我想知道我是否应该执行上面的代码并读入数组ONCE已经选择了一个类别 - 但这可能会导致它为用户拖延。

I am wondering whether I should do the above code and read in to the array ONCE a category has been selected - but that might then cause it to stall for the user.

有什么想法吗?!

ps)我还需要考虑一下Retina的显示效果。有600多张图片,复制它们意味着我的二进制大小会火箭!

ps) I also need to have a think about Retina display. With 600+ images, duplicating them would mean my binary size would rocket!!

推荐答案

使用字符串编写路径字典/数组,然后根据需要加载/卸载图像(懒惰加载),如果需要的话在你的程序中与之接口的结构。

compose your path dictionaries/arrays using strings, then load/unload images as needed (load lazily), if you need such a structure to interface with in your program.

600 HQ图像将超出内存限制,这是浪费,因为用户将在给定时间看到这些图像中有多少?资源是非常有限的,而且hq图像需要很大的空间。

600 HQ images will exceed the memory limits, and it's wasteful because the user will see how many of these images at a given time? resources are quite limited, and hq images require a lot of space.

如果你必须显示一堆缩略图,那么这些缩略图可能会缩小并轻松导出以便你可以在合理的时间内显示所有图像,同时使用合理数量的内存(同样,只在可能的情况下懒洋洋地加载并在不容易查看时释放图像)。

if you have to display a bunch of thumbnails, those may be shrunk and exported easily enough so you can display all the images in a reasonable amount of time, while using a rational amount of memory (again, just load lazily where possible and release the image when not very easily viewed).

这篇关于加载iphone nsmutablearray图像库的最佳方法(600多项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆