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

问题描述

限时删除!!

我如何能够确定/计算(与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)

感谢您的解决方案!

更新: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位图有一个直接的方式来查询的字节大小: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

----样品code

----Sample code

    @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();
        }
    }

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

1403页,肝出来的..

09-07 01:29