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.
这篇关于在不加载到内存的情况下获取图像的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在不加载到内存的情况下获取图像的大小


- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01