iOS应用程序中没有CATiledLayer的巨大图像? [英] Huge images in iOS app without CATiledLayer?

查看:309
本文介绍了iOS应用程序中没有CATiledLayer的巨大图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张约7000x6000像素的图片。我需要这是一个scrollview / imageView在我的应用程序,但这是巨大的显示方式。它应该是一种地图。我希望保持应用程序的大小到最小,而图像只是大约13mb在.jpg。在.png它是超过100mb,这是不能接受的。许多人建议 CATiledLayer 作为选项,但我相信这将导致更大的文件大小。无论如何,我试图用 CATiledLayer ,并在TileCutter创建自己的瓷砖(.jpg中的瓷砖),并且尺寸不是太糟糕。但我有错误的地方。 iOS版本 CATiledLayer 对我来说是一个谜,我找不到解决方法。我收到一个错误,说一些关于java等效的索引超出数组,即使数组有特定的索引的内容。
它有一个方法返回一个数组。该数组包含.plist的数据。在返回之前我注销数组的内容,给我好的数据。该通话尝试访问

I have an image at about 7000x6000px. I need this to be in a scrollview/imageView in my app, however this is way to huge for display. It is supposed to be a kind of map. I was hoping to keep the size of the app to the minimum, and the image is just about 13mb in .jpg. In .png it is over 100mb, which is unacceptable. Many have suggested CATiledLayer as an option, but I believe this would result in even bigger file sizes. Anyway, I tried to do it with CATiledLayer, and create my own tiles in TileCutter, (tiles in .jpg), and the size wasn't too bad. But I am having errors all over the place. The iOS version of CATiledLayer is a mystery to me, and I can't find a way to solve this. I get an error saying something about the java-equivalent "index out of bounds of array", even though the array has content at that specific index.. It has a method which returns an array. The array contains data of a .plist. Before the return I log out the content of the array, giving me good data. The call is trying to access

[array objectAtIndex:0]

并将其放在字典中,但抛出OutOfBounds。当注销整个数组时,我可以清楚地看到内容,但是当注销时

and put it in a dictionary, but throws OutOfBounds. When logged out the whole array, I can clearly see the content, but when logged out

NSLog("%@",[method objectAtIndex]); I get the same exception.

无论如何, CATiledLayer 问题。我已经逆向工程的PhotoScroller项目没有运气。任何人都有其他解决方案?

Anyway, CATiledLayer has given me nothing but problems. I have been reverse-engineering the PhotoScroller project with no luck. Anyone have any other solutions?

感谢。

推荐答案

这个真正整洁的项目,PhotoScroller,使用CATiledLayer,让你滚动几个图像和缩放它们。这似乎真的很整洁,直到我发现苹果欺骗和预先平铺的图像(大约800平铺保存为文件在捆绑!)

Apple has this really neat project, PhotoScroller, that uses CATiledLayer and lets you scroll through several images and zoom them. This seemed really neat until I found out that Apple "cheated" and pre-tiled the images (about 800 tiles saved as file in the bundle!)

我需要类似的能力,但是不得不从网络下载图像。因此来自 PhotoScrollerNetwork 。使用TiledImageBuilder你可以下载(或从磁盘读取)大量的图像 - 我甚至测试了一个18000x18000的图像 - 它的工作原理。

I had need for a similar capability, but had to download the images from the network. Thus came about PhotoScrollerNetwork. With the TiledImageBuilder you can download (or read from disk) massive images - I even tested a 18000x18000 image - and it works.

这个类做的是开始平铺图像因为它下载(当使用libjpegturbo)或可以保存文件,然后平铺(需要更长)。

What this class does is start tiling the image as it downloads (when using libjpegturbo) or can save the file then tile (takes longer). The class figures out how many levels of detail are needed to show the image at full resolution and sized to fit in the containing view (a scrollview).

这个类使用了一个包含视图的视图(一个滚动视图)来显示图像的全分辨率和大小。磁盘缓存来保存磁贴,但使用和旧的Unix技巧创建一个文件,打开它,然后取消链接它,以使磁贴从来没有真正得到保存 - 一旦类被释放(和文件描述符关闭)的瓷砖释放或者如果您的应用崩溃,他们也会被释放。

The class uses the disk cache to hold the tiles, but uses and old Unix trick of creating a file, opening it, then unlinking it so that the tiles never really get saved - once the class is dealloced (and the file descriptor closed) the tiles are freed (or if your app crashes they get freed too.

有人在iPad 1上遇到了问题,其内存相当有限,因此该类现在限制了对文件系统的使用同时加载多个图像我今年在WWDC上与iOS内核管理器讨论,在向他解释了节流技术之后,他说算法(关于管理磁盘缓存使用量)可能是最好的技术

Someone had problems on an iPad 1 with its quite limited memory, so the class now throttles its use of the file system when concurrently loading multiple images. I had a discussion with the iOS kernel manager at WWDC this year, and after explaining the throttling technique to him, he said the algorithm (on managing the amount of disk cache usage) was probably the best technique that could be used.

这篇关于iOS应用程序中没有CATiledLayer的巨大图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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