智慧型北京第5天

2021-07-23 15:16:37 字數 2139 閱讀 6718

//網路讀取資料

public class networkcacheutils

// 根據傳入的url給傳入的imageview設定

public void getbitmapfromnet(imageview ivpic, string url)

public class bitmaptask extends asynctask

@override

protected bitmap doinbackground(object... params)

//@override

protected void onprogressupdate(void... values)

@override

protected void onpostexecute(bitmap result)

}} }

/* */

private bitmap downloadbitmap(string url)

} catch (exception e) finally

return null;

}}

public class sdcardcacheutils 

fileoutputstream fileoutputstream = new fileoutputstream(file);

//儲存到流中 jpeg格式 100是不壓縮

bitmap.compress(compressformat.jpeg, 100, fileoutputstream);

} catch (exception e1)

} //從sdcard中獲取bitmap物件

public bitmap getdatabysdcard(string url)

} catch (exception e)

return null;

}}

public class roomcacheutils };}

//儲存物件在記憶體中

public void setdatatoroom(string url , bitmap bitmap )

//從記憶體中讀取bitmap物件

public bitmap getdatabyroom(string url)

}

public class mybitmpautils 

public void display(imageview ivpic,string url)

//2.從sdcard中讀取。第二

bitmap bitmap = sdcardcacheutils.getdatabysdcard(url);

if(bitmap!=null)

//3.從網路中讀取,第三

networkcacheutils.getbitmapfromnet(ivpic, url);

}}

//一般物件:hashmaphashmap = new hashmap();

//軟引用物件:hashmap>hashmap = new hashmap>();

//softreferencereference = hashmap.get(url);

private lrucachelrucache; //使用最少最近演算法

lrucache.put(url, bitmap);//儲存

bitmap bitmap = lrucache.get(url);//獲取

//對進行壓縮

bitmapfactory.options options = new bitmapfactory.options();

options.insamplesize = 2 ;//寬高縮小為原來的2分之一

options.inpreferredconfig = bitmap.config.rgb_565;

bitmap bitmap = bitmapfactory.decodestream(inputstream,null,options);

5天學python python 學習第5天

字典增刪改查 dic1 dic1 asdas dfdsf 新增 預設最後乙個 print dic1 dic1 age 20 如果有建 則值覆蓋 print dic1 dic1.setdefault weight 有建值對 不做任何改變 沒有新增建值對 dic1.setdefault weight 1...

python第5天學習

函式以def開頭,後面接函式名和圓括號 函式執行的 以冒號為起始,並且縮排。return結束函式選擇返回乙個值給呼叫方不用表示式return相當於返回none。可以沒有返回值。def function d ddd return c 函式的呼叫 temp function s wemp是s print...

戒菸進入第5天!

上上次和老爸通 老爸建議我戒菸 8月19晚,gf提出要我戒菸,想起老爸的建議,自己這些天也有要改變自己的想法 就答應把最後一包煙在這一天抽完,月 開始 月 日周 上班沒有抽菸,下班後挺驕傲的,去超市買了些糖果,乙個勁的喝咖啡 糖果太甜,月 日週六,很難受,但是最後還是堅持下來了 之間多次向gf要求抽...