凡到底是位图getByteCount()? [英] Where the heck is Bitmap getByteCount()?

查看:128
本文介绍了凡到底是位图getByteCount()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

据谷歌文档位图有一个方法<一href="http://developer.android.com/reference/android/graphics/Bitmap.html#getByteCount%28%29">getByteCount()要做到这一点,但它不是present在SDK2.2,还没有尝试过其他的,但没有提到它是德precated或API的支持是任何不同的API 1 ...所以其中这个神秘的方法隐藏?这将真正高兴能ALBE简单做

  bitmap.getByteCount()
 

解决方案

如果您通过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.

这篇关于凡到底是位图getByteCount()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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