圖片加載的緩存工具類

    // 圖片加載的緩存工具類,安卓自帶的方法
    public static BitmapFactory.Options getHeapOpts(File file) {
        BitmapFactory.Options opts = new BitmapFactory.Options();
        // 數字越大讀出的圖片佔用的heap必須越小,不然總是溢出
        if (file.length() < 20480) { // 0-20k
            opts.inSampleSize = 1;// 這裏意爲縮放的大小 ,數字越多縮放得越厲害
        } else if (file.length() < 51200) { // 20-50k
            opts.inSampleSize = 2;
        } else if (file.length() < 307200) { // 50-300k
            opts.inSampleSize = 4;
        } else if (file.length() < 819200) { // 300-800k
            opts.inSampleSize = 6;
        } else if (file.length() < 1048576) { // 800-1024k
            opts.inSampleSize = 8;
        } else {
            opts.inSampleSize = 10;
        }
        return opts;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章