Reputation: 107
My app only performs a certain function if an image in external memory has a file size on disk larger than 400KB, so I need to know what the size of the image is, but this
image.getByteCount() / 1024
just returns the size of the decoded Bitmap rather than the file size. I also tried using
image_file.length() / 1024
but this method just return 0 KB. Is there anyway to find the file's actual size on the disk?
Upvotes: 0
Views: 257
Reputation: 75629
Is there anyway to find the file's actual size on the disk?
No. Mainly because of compression which may give different results depending on the bitmap content. So in fact means, you need to create the file to figure out how big it is. You can keep that file data in memory and then check disk space prior dumping (or not) that memory to a file.
Note this approach may not work if you need to work with big bitmaps or big images due to risk of running out of memory or hitting memory limits. Still, may be worth checking though.
EDIT
If the image is already a compressed file in external memory is there a way to find it?
If you have the file on disk already, just call length()
on it (docs).
Upvotes: 1