有什么方法可以获取位图的存储大小? [英] Is there any way to get the storage size of a Bitmap?

查看:52
本文介绍了有什么方法可以获取位图的存储大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在下载一些图像,我想知道是否有任何方法可以获取已下载位图的大小.这是一个简单的问题,但我似乎无法通过Google找到解决方案.

In my app I am downloading some images and I want to know if there is any way I can get the size of a Bitmap that I have downloaded. It's a simple question but i can't seem to find the solution through Google.

这是下载代码:

Bitmap b = BitmapFactory.decodeStream((InputStream) new URL(theImageUrl).getContent());

推荐答案

首先将位图转换为字节[],然后可以获取位图的大小

First convert the Bitmap into byte[] then you can get the size of bitmap

尝试以下代码

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

这篇关于有什么方法可以获取位图的存储大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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