[英]How to get the size of an drawable image in android
目前我在android中的可繪制圖像中工作,現在我想以KB為單位獲取可繪制圖像的大小,我該如何獲取它,歡迎任何想法。
我在這里獲取默認的應用程序圖標並存儲在可繪制數組中,是否為每個圖標創建一個新文件以獲取長度是一個好主意? 請提出任何更好的主意,謝謝
這是個主意。 將可繪制圖像轉換為字節數組...數組長度是可繪制圖像的大小(以字節為單位)。 不知道是否有更好的方法...
我認為您必須將其存檔。 但不確定是否有效
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();
使用file.length()
應該可以為您提供文件大小。
我不知道這是否在所有情況下都適用,但是您可以使用以下方法:
Drawable d;
long kbsize = ((BitmapDrawable)d).getBitmap().getByteCount() / 1024;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.