如何在iphone sdk中以编程方式获取图像占用的内存大小? [英] how to get the memory size occupied by a image programatically in iphone sdk?

查看:69
本文介绍了如何在iphone sdk中以编程方式获取图像占用的内存大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印加载特定图像时图像占用的内存量。谁能有想法?
请帮帮我
谢谢
Lakshmi

i want to print how much memory is occupying by a image when that particular image is loaded. can anyone have idea? Please help me Thank You Lakshmi

推荐答案

UIImage 没有提供告知内存底层数据的明显方法。但是,我们可以使用Core Graphics为我们提供估算。您可以通过执行来估计图像占用的内存

UIImage provides no obvious way of telling the memory of the underlying data. However we could use Core Graphics to give us the estimate. You could probably get an estimate of the memory occupied by an image by doing

size_t imageSize = CGImageGetBytesPerRow(image.CGImage) * CGImageGetHeight(image.CGImage);

但我建议您不要对此进行任何图像管理。你真的不知道你会有多少记忆。尽量减少已加载到内存中的图像数量。基本上,根据需要进行优化。

But I suggest you don't base any image management on this. You really don't know how much memory you will have with you. Try to minimize how many images you've loaded into memory. Basically, optimize as necessary.

这篇关于如何在iphone sdk中以编程方式获取图像占用的内存大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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