照片库怎么显示这么多图片呢?
扩展一下这个主题,......而不崩溃?我从 UIImageViews 的照片库中加载了大约 15 张全尺寸图像,并收到内存不足警告,最终导致应用程序崩溃。这些图像的大小从 250KB 到 400KB 左右。 UIImageViews 设置为宽高比。
照片库似乎加载较小文件大小的图像版本,而不仅仅是调整其比例。有谁知道它如何能够显示这么多而不会因为内存使用而崩溃?
To extend on the subject, ...without crashing? I load about 15 full size images from the photo library in UIImageViews and get out of memory warnings and eventually an app crash. These images range from around 250KB to 400KB. The UIImageViews are set to aspect fit.
The photo library seems to load smaller file size versions of images, rather than just resizing their proportions. Does anyone know how it is able to display so many without crashing because of memory usage?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如你所说,你会想要调整图像的大小。调整图像大小并不像您想象的那么明显,但这并不难:
当然,您需要确保释放旧图像,以便可以回收内存。最好的方法可能是使用 +imageWithContentsOfFile: ,因为它明确不缓存。
As you say, you'll want to resize the images. Resizing an image isn't quite as obvious as you'd think, but it's not hard:
Of course you'll want to make sure you release your old images so you can reclaim the memory. The best approach is probably to use
+imageWithContentsOfFile:
since it explicitly doesn't cache.照片库可能执行许多内存优化:
为了让您的生活更轻松,我建议使用 Facebook Three20 库,其中包括照片查看器:
该项目有一个很好的示例代码,因此您可以从那里开始。顺便说一句,这与 Facebook iPhone 应用程序中使用的视图相同。它的外观如下:
The photo library performs many memory optimizations, propably:
To make your life easier, I recommend using the Facebook three20 library, which includes a photo viewer:
The project has a nice sample code, so you can start from there. By the way, this is the same view used in the Facebook iPhone app. Here is how it looks like: