2

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

这是下载的代码:

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

3 回答 3

3

首先将Bitmap转换为byte[]然后你可以得到位图的大小

尝试使用以下代码

Bitmap bitmap = your bitmap object
ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] imageInByte = stream.toByteArray();
long length = imageInByte.length;
于 2011-06-21T11:42:30.010 回答
2
File file = new File("infilename");

// Get the number of bytes in the file
long length = file.length();
于 2011-06-21T11:23:42.860 回答
1

使用b.getByteCount();或者你想在下载之前查询服务器的大小?

编辑:此方法仅适用于 API 级别 12。

于 2011-06-21T11:41:09.400 回答