解码后位图字节大小? [英] Bitmap byte-size after decoding?

查看:37
本文介绍了解码后位图字节大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定/计算位图的字节大小(使用 BitmapFactory 解码后)?我需要知道它占用了多少内存空间,因为我正在我的应用程序中进行内存缓存/管理.(文件大小不够,因为这些是 jpg/png 文件)

How can I determine/calculate the byte size of a bitmap (after decoding with BitmapFactory)? I need to know how much memory space it occupies, because I'm doing memory caching/management in my app. (file size is not enough, since these are jpg/png files)

感谢您提供任何解决方案!

Thanks for any solutions!

更新:getRowBytes * getHeight 可能会起作用.. 我会以这种方式实现它,直到有人提出反对它.

Update: getRowBytes * getHeight might do the trick.. I'll implement it this way until someone comes up with something against it.

推荐答案

getRowBytes() * getHeight() 对我来说似乎工作正常.

getRowBytes() * getHeight() seems to be working fine to me.

更新我大约 2 岁的答案:由于 API 级别 12 Bitmap 有直接查询字节大小的方法:http://developer.android.com/reference/android/graphics/Bitmap.html#getByteCount%28%29

Update to my ~2 year old answer: Since API level 12 Bitmap has a direct way to query the byte size: http://developer.android.com/reference/android/graphics/Bitmap.html#getByteCount%28%29

----示例代码

    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
    protected int sizeOf(Bitmap data) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
            return data.getRowBytes() * data.getHeight();
        } else {
            return data.getByteCount();
        }
    }

这篇关于解码后位图字节大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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