在不加载到内存的情况下获取图像的大小 [英] Get size of image without loading in to memory

查看:22
本文介绍了在不加载到内存的情况下获取图像的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 .png 图像(ETA: 但格式也可以是 JPEG 或其他格式),我将在 UITableViewCells.现在,为了获得行高,我加载图像,获取它们的 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 UITableViewCells. 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屋!

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