2

Is this right to get Bitmap size after encoding? what if I need to use it before encoding when select image?

if (v == buttonUpload) {
        if (bitmap.getByteCount() > 1000000) {
            Toast.makeText(getActivity().getApplicationContext(), "please check image size!!", Toast.LENGTH_SHORT).show();
        } else {
            uploadImage();
        }
    }
mohammed02
  • 85
  • 5
  • What do you consider the size? Is you select an image then i think you select an image file by Gallery app. So then file size. You give not enough info to help you. – greenapps Feb 14 '16 at 11:13
  • Yes this condition after selecting image from Gallery and when he click on upload button to upload image this condition will work to see bitmap size but sometimes won't work – mohammed02 Feb 14 '16 at 11:15

2 Answers2

0

If you want to check the size of a compressed bitmap image please use:

file.length();
Edik
  • 1
  • 3
  • So I have to convert bitmap image to integer. – mohammed02 Feb 14 '16 at 11:28
  • Nonsense. Bitmaps cannot be converted to integers. – greenapps Feb 14 '16 at 11:32
  • No need for converting, because you can get the file length with this method. If you check it by using byteCount-method or sizeOf-method, the memory will always be the same, since the used memory is not the same as the actual filesize of bitmap-files. – Edik Feb 14 '16 at 11:32
  • Bitmap-files ? Never heard of in an Android context. Please give an example. – greenapps Feb 14 '16 at 11:34
  • File file = new File(absFileName); file.length(); As answered here: http://stackoverflow.com/questions/6833909/get-size-of-bitmap-android Was using this method and it was working fine. – Edik Feb 14 '16 at 11:38
  • More explain please, I'm talking about bitmap only after that was encoded – mohammed02 Feb 14 '16 at 11:44
  • `to check the size of a compressed bitmap image please use: file.length();`. That still is nonsense. Sorry. – greenapps Feb 14 '16 at 12:05
0

after encoding

So, after you've saved the bitmap as a PNG or a JPEG? (Using bitmap.compress)

If that's the case, then you can simply get the file and find out it's size using file.length() which will give you the byte size of the file (image file, in this case). Look up Saving Files for more information on working with files.

Or are you trying to figure out the in memory size of the bitmap object? In that case you can use profiling (through DDMS). You can read more about it here

Aditya Anand
  • 776
  • 2
  • 9
  • 29