凡到底是位图getByteCount()?位图、getByteCount

2023-09-06 02:14:37 作者:红颜情断肠

我知道Android平台是一个巨大的烂摊子,在复杂和过度设计的,但严重的是得到一个位图的大小,是不是真的有必要做所有这些转换?

 位图位=您的位图对象
ByteArrayOutputStream流=新ByteArrayOutputStream();
    bitmap.com preSS(Bitmap.Com pressFormat.JPEG,100,流);
    byte []的imageInByte = stream.toByteArray();
长长度= imageInByte.length;
 

据谷歌文档位图有一个方法getByteCount()要做到这一点,但它不是present在SDK2.2,还没有尝试过其他的,但没有提到它是德precated或API的支持是任何不同的API 1 ...所以其中这个神秘的方法隐藏?这将真正高兴能ALBE简单做

  bitmap.getByteCount()
 

解决方案 MFC GetBitmap加载位图问题 请看图

如果您通过API 8级过滤(= SDK 2.2),你会看到位图#getByteCount()是灰色的,这意味着该方法并不present在API层面。

getByteCount()中添加了API级别12。

I know the Android platform is a huge mess, over complicated and over-engineered, but seriously to get the size of a bitmap, is it really necessary to do all those conversions?

Bitmap bitmap = your bitmap object
ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] imageInByte = stream.toByteArray();
long length = imageInByte.length;

According to Google Documentation Bitmap has a method getByteCount() to do this, however it is not present in SDK2.2, haven't tried other's but there is no mention of it being deprecated or that API support is any different from API 1... So where is this mysterious method hiding? It would really nice to be albe to simple do

bitmap.getByteCount()

解决方案

If you filter by API Level 8 (= SDK 2.2), you'll see that Bitmap#getByteCount() is greyed out, meaning that method is not present in that API level.

getByteCount() was added in API Level 12.

 
精彩推荐