获取图像的大小,而不加载到内存 [英] Get size of image without loading in to memory
问题描述
我有几个要显示的 .png
图片( ETA:,但格式也可以是JPEG或其他格式) UITableViewCell
s。现在,为了得到行的高度,我加载图像,获取他们的 size
属性,并使用它来计算出多高的行(计算任何必要的改变,因为大多数图像在显示之前调整大小)。为了加速和减少内存使用,我想要能够获得 size
,无需加载图像。是否有办法做到这一点?
I have several .png
images (ETA: but the format could also be JPEG or something else) that I am going to display in UITableViewCell
s. Right now, in order to get the row heights, I load in the images, get their size
properties, and use that to figure out how high to make the rows (calculating any necessary changes along the way, since most of the images get resized before being displayed). In order to speed things up and reduce memory usage, I'd like to be able to get size
without loading the images. Is there a way to do this?
注意:我知道有很多快捷键可以实现来消除这个问题,由于几个原因,我无法提前调整图片大小或提前收集图片大小,迫使我在运行时获取此信息。
Note: I know that there are a number of shortcuts I could implement to eliminate this issue, but for several reasons I can't resize images in advance or collect the image sizes in advance, forcing me to get this info at run time.
推荐答案
从iOS SDK 4.0开始,此任务可以使用ImageIO框架( CGImageSource ...
)完成。我已在此回答类似问题。
As of iOS SDK 4.0, this task can be accomplished with the ImageIO framework (CGImageSource...
). I have answered a similar question here.
这篇关于获取图像的大小,而不加载到内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!