Bitmap getByteCount() 到底在哪里? [英] Where the heck is Bitmap getByteCount()?

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

问题描述

我知道 Android 平台一团糟,过于复杂和过度设计,但要获得位图的大小,真的有必要进行所有这些转换吗?

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;

根据 Google 文档 Bitmap 有一个方法 getByteCount() 这样做,但是它在 SDK2.2 中不存在,还没有尝试其他的但是没有提到它被弃用或者 API 支持与 API 1 有任何不同......那么这是哪里神秘方法隐藏?能做简单的事情真是太好了

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()

推荐答案

如果您按 API 级别 8 (= SDK 2.2) 过滤,您将看到 Bitmap#getByteCount() 变灰,表示该 API 级别不存在该方法.

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() 已在 API 级别 12 中添加.

getByteCount() was added in API Level 12.

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

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