如何获得在Android的图像的大小?如何获得、图像、大小、Android

2023-09-06 01:18:22 作者:金不唤伪君子

我能够获得的图像的高度和宽度。但有一个检索的大小(以字节为单位或KB或MB),用于存储在手机图像的方法?

I'm able to get the height and width of an image. But is there a method to retrieve the size (in bytes or kb or mb) for an image stored in the phone?

推荐答案

感谢您的答案。这就是我终于解决了它:

Thank you for your answers. This is how I finally resolved it:

 Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), 
            R.drawable.ic_launcher);


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

鸭preciate您的时间和答案:)

Appreciate your time and answers :)