currently im working in drawable images in android, and now i want to get the size the drawable image in KB , how can i get it, any ideas are welcome.
Here im getting the default application icons and storing in an drawable array, is creating a new file for each icon for getting length is a good idea? Please suggest any better idea,thanks
Here's an idea. Convert the drawable image to a byte array... the array length is the size of the drawable image in bytes. Not sure if there is a better way...
I think u have to make it a file. But not sure whether it works
File root = new File(Environment.getExternalStorageDirectory()
+ File.separator + "temp" + File.separator);
root.mkdirs();
File file= new File(root, "temp.png");
FileOutputStream fOut = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 100, fOut);//bmp is bitmap of ur image
fOut.flush();
fOut.close();
Using file.length()
should give you the file size.
I don't know if this will work in all situations but you can use this:
Drawable d;
long kbsize = ((BitmapDrawable)d).getBitmap().getByteCount() / 1024;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.