質問

画像の高さと幅を得ることができます。しかし、電話に保存されている画像のサイズ(バイトまたはKBまたはMB)を取得する方法はありますか?

役に立ちましたか?

解決

答えてくれてありがとう。これが私が最終的にそれを解決した方法です:

 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; 

あなたの時間と答えに感謝します:)

他のヒント

新しいものを作成する必要があります File ...などのオブジェクト

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

あなたがビットマップについて話していると仮定すると(そして画像ビューではありません)、方法があります bitmap.getByteCount().

 File file = new File("/sdcard/imageName.jpeg");
 long length = file.length();
 length = length/1024;
 System.out.println("File Path : " + file.getPath() + ", File size : " + length +" KB");

これにより、右クリックでファイルの詳細が表示されると、コンピューターで一致する真のサイズが返されます。

File file = new File("/sdcard/my_video.mp4");
long length = file.length() / 1024; // Size in KB
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top