Reputation: 12237
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.
here's the code for downloading:
Bitmap b = BitmapFactory.decodeStream((InputStream) new URL(theImageUrl).getContent());
Upvotes: 2
Views: 2747
Reputation: 7051
Use b.getByteCount(); or do you want to query the size form the server before you download?
EDIT: This method is only available for API Level 12.
Upvotes: 1
Reputation: 53687
First convert the Bitmap into byte[] then you can get the size of bitmap
Try with thye following code
Bitmap bitmap = your bitmap object
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
long length = imageInByte.length;
Upvotes: 3
Reputation: 2346
File file = new File("infilename");
// Get the number of bytes in the file
long length = file.length();
Upvotes: 2