有什么方法可以获取位图的存储大小?

编程入门 行业动态 更新时间:2024-10-11 19:19:56
本文介绍了有什么方法可以获取位图的存储大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的应用程序中,我正在下载一些图像,我想知道是否有任何方法可以获取已下载位图的大小.这是一个简单的问题,但我似乎无法通过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(); bitmappress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] imageInByte = stream.toByteArray(); long length = imageInByte.length;

更多推荐

有什么方法可以获取位图的存储大小?

本文发布于:2023-10-26 17:34:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530853.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   位图   大小   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!