在没有预切瓦片的iOS上显示大图像 [英] Display large images on iOS without precut tiles

查看:302
本文介绍了在没有预切瓦片的iOS上显示大图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个相机应用程序,将图像数据保存到沙箱中的单个JPEG文件中。图像平均大小约为2mb。

I'm building a camera application that saves the image data to a single JPEG file in the sandbox. The images average at about 2mb in size.

问题:我无法在照片查看器中显示图像,因为内存中有一些图像会引发内存警告并使图像非常滚动慢。

Problem : I cannot display the images in a photo viewer because having a few images in memory throws memory warnings and makes scrolling through the images very slow.

我无法将图像分割成图块并将其保存到磁盘,因为这比显示单个图像更昂贵。我尝试在捕获时将图像分割成图块,但在5S上平均花费5 1/2秒将所有图块保存到磁盘。当应用程序在旧设备上执行时,它只会变得更糟。这非常糟糕,因为如果用户在保存中存在应用程序,该怎么办?我将丢失磁贴并且没有未压缩的原始文件以便稍后找到丢失的磁贴。

I cannot split the image into tiles and save them to disk because that's even more expensive than displaying the single image. I tried splitting the image up into tiles upon capture, but on the 5S it took, on average, 5 1/2 seconds to save all the tiles to disk. It will only get worse from there as the app is executed on older devices. This is very bad because what if the user exists the app in the middle of the save? I will have missing tiles and no uncompressed original file to find missing tiles later.

问题:显示完整尺寸图像的最佳方式是什么不会导致内存问题并保持滚动速度快? App Store上的大量相机应用程序就是这样做的,照片应用就是这样做的,必须有一个很好的解决方案。

Question : what's the best way to show a full sized image without causing memory issues and keeping the scrolling fast? Tons of camera applications on the App Store do this and the Photos app does this, there has to be a good solution.

注意:我我正在显示图像的缩略图,然后在另一个线程中从磁盘加载完整大小的图像。完成完整尺寸的图像加载后,我会在主线程上显示完整尺寸的图像。这消除了内存问题,因为我一次只在内存中有一个完整大小的图像,有两个缩略图,但仍然导致在滚动视图上滞后,因为在主线程中绘制完整大小的图像仍然非常昂贵。

Note : I'm currently showing a thumbnail of the image and then loading the full size image from disk in another thread. Once the full size image loading has finished, I present the full size image on the main thread. This removes the memory issues because I only have one full size image in memory at once, with two thumbnails, but still causes lagging on the scrollview because drawing the full size image in the main thread is still pretty expensive.

我非常感谢任何输入!

推荐答案

单程处理这个是平铺图像。
您可以将大型解压缩图像保存为磁盘作为一系列图块,并且当用户平移时只拉出您需要实际显示的图块。您一次只需要内存中的1个磁贴,因为您将其绘制到屏幕上,然后将其抛出并加载下一个磁贴。 (您可能希望在内存中缓存可见的图块,但这是一个实现细节。即使将整个图像作为图块也可以减轻内存压力,因为您不需要一个大的连续块。)

One way to deal with this is to tile the image. You can save the large decompressed image to "disk" as a series of tiles, and as the user pans around pull out only the tiles you need to actually display. You only ever need 1 tile in memory at a time because you draw it to the screen, then throw it out and load the next tile. (You'll probably want to cache the visible tiles in memory, but that's an implementation detail. Even having the whole image as tiles may relieve memory pressure as you don't need one large contiguous block.)

这就是像Photoshop这样的应用程序处理这种情况的方式。

This is how applications like Photoshop deal with this situation.

第二种方式我建议你使用
查看 Apple 中的示例以进行大型处理图像称为PhotoScroller。图像已经平铺。如果您需要在Cocoa中平铺图像的示例,请查看 cimgf.com

Second way which I suggest you is to check the example from Apple for processing large images called PhotoScroller. The images have already been tiled. If you need an example of tiling an image in Cocoa check out cimgf.com

希望这会对你有帮助。

这篇关于在没有预切瓦片的iOS上显示大图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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