如何在iPhone / iPad上存储非常大的图像 [英] How to store a very large image on an iPhone/iPad

查看:206
本文介绍了如何在iPhone / iPad上存储非常大的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为iOS应用程序存储非常大的图像的最佳方法是什么?我希望一个应用程序能够查看可能数百兆字节的图像,可能与jpeg一样多达一千兆字节。我需要能够存储图像并检索所选区域以供显示。

What's the best way to store a very large image for an iOS app? I want an app to be able to view images that might be hundreds of megabytes, perhaps as much as a gigabyte as jpeg. I need to be able to store the image and retrieve selected areas for display.

目前,图像被切割成512x512像素图块并作为jpeg文件存储在目录树中成千上万的瓷砖(实际上是包含下采样的图像金字塔)。

Currently the images are cut into 512x512 pixel tiles and stored as jpeg files in a directory tree with tens of thousands of tiles (actually an image pyramid including downsamples).

忽略显示图像的问题,我对最有效,最易于管理的存储方式感兴趣设备上的这些数据:文件,就像它们目前一样,是在sqlite数据库中还是其他什么?

Ignoring the question of displaying the image, I'm interested in the most efficient, manageable way to store this data on the device: files, like they currently are, in an sqlite database or something else?

问题的第二部分。应用程序可以存储的数据量是否有限制,或者应用程序是否可以将数据导入到设备的存储限制。我在这里询问应用程序在安装后导入的数据。

Second part to the question. Is there a limit to the amount of data an app can store, or can an app keep importing data up to the storage limit of the device. I'm asking here about data that an app imports after it's installed.

推荐答案

解决方法是先解决这个问题。因此可以根据需要从文件系统中快速检索切片。非常大的图像的一个问题是大多数解决方案需要将整个图像渲染到上下文中,从而消耗大量的存储器。在iOS等内存有限的系统上,解决此问题的方法是使用 libjeg libjpegturbo <等库/ strong>一次渲染一行图像,然后将像素保存到原始文件中。直接执行此操作的缺点是,当您需要一个磁贴时,您需要遍历文件系统以查找磁贴的每一行。因此,更好的解决方案不仅是递增扫描,而且还递增地平铺。您可以使用mmap将文件映射到您需要的区域,这样您就可以真正减少内存消耗。也就是说,您可以在iOS上破坏统一缓冲区队列,以免应用程序崩溃,甚至整个系统崩溃!

The solution to this is to pre tile the enormous image so the tiles can be quickly retrieved from the file system on an as needed basis. One problem with very large images is that most solutions require the whole image to be rendered into a context, consuming vast amounts of memory. On a system like iOS, where memory is limited, the way to solve this is to use a library like libjeg or libjpegturbo to render an image a line at a time, then save the pixels into a raw file. The downside to doing this directly is that when you need one tile, you need to jump all over the file system finding each row of a tile. Thus a better solution is to not only incrementally scan, but incrementally tile too. You can use mmap to map the file into just the area you need, so you can really minimize memory consumption. That said, you can thrash the Unified Buffer Queue on iOS so badly the app crashes, or even the whole system!

如果您对如何实施上述解决方案感到好奇,github上有一个免费提供的项目 - PhotoScrollerNetwork - 完成上述所有工作。

If you are curious about how to implement the above solution, there is a freely available project on github - PhotoScrollerNetwork - that does all the above.

这篇关于如何在iPhone / iPad上存储非常大的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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