How to get the size of an image in Android?

前端 未结 5 706
没有蜡笔的小新
没有蜡笔的小新 2020-12-28 10:09

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?

5条回答
  •  执念已碎
    2020-12-28 10:48

    You just need to create a new File object such as...

    String filepath = Environment.getExternalStorageDirectory() + "/file.png";
    File file = new File(filepath);
    long length = file.length();
    

提交回复
热议问题