Bitmap簡介
Bitmap:是一種存儲像素的數(shù)據(jù)結(jié)構(gòu)靴寂,通過這個對象可以得到一系列的圖像屬性蛾魄。
獲取圖片的Bitmap
由于Bitmap的構(gòu)造方法私有化征峦,所以我們不能在外部直接實例化一個Bitmap對象情屹。我們只能通過BitmapFactory來得到Bitmap對象柏锄。
BitmapDrawable方法:
你可以創(chuàng)建一個構(gòu)造一個BitmapDrawable對象酿箭,比如通過流構(gòu)建BitmapDrawable:
BitmapDrawable bmpMeizi = new BitmapDrawable(getAssets().open("pic_meizi.jpg"));
Bitmap mBitmap = bmpMeizi.getBitmap();
img_bg.setImageBitmap(mBitmap);
BitmapFactory方法:
方法 | 說明 |
---|---|
decodeStream(InputStream is) | 從輸入流讀取圖片 |
decodeFile(String pathName) | 從文件讀取圖片 |
decodeResource(Resources res, int id) | 從資源文件讀取圖片 |
Bitmap與BitmapDrawable复亏,Drawable和Canvas的關(guān)系
Bitmap存儲像素信息
Drawable 儲存的是 對 Canvas 的一系列操作
BitmapDrawable轉(zhuǎn)換成是Drawable的子類,Bitmap可以通過BitmapDrawable轉(zhuǎn)換成Drawable