1

currently i m 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 i m 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

2

3 Answers 3

4

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...

Sign up to request clarification or add additional context in comments.

2 Comments

That's the only way I know of. If you need it in KB, just divide the array.length by 1024. :)
hi alex, i got the expected result through this technique, Thanks for ur reply.
1

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.

2 Comments

he wants from drawable not from sdcard.
yea. i asked him to save it to sd card and check for the file size
1

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; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.