最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android Drawable和Bitmap的轉(zhuǎn)換實例詳解

 更新時間:2017年05月17日 08:38:22   投稿:lqh  
這篇文章主要介紹了Android Drawable和Bitmap的轉(zhuǎn)換實例詳解的相關(guān)資料,需要的朋友可以參考下

Android Drawable和Bitmap的轉(zhuǎn)換實例詳解

通常我們需要通過代碼去設(shè)置圖片,就需要設(shè)置圖片Bitmap和Drawable的轉(zhuǎn)換,下面整理了幾種方式

一、Bitmap轉(zhuǎn)Drawable

Bitmap bm=xxx; //xxx根據(jù)你的情況獲取
BitmapDrawable bd=new BitmapDrawable(bm);//因為BtimapDrawable是Drawable的子類,最終直接使用bd對象即可。

二、 Drawable轉(zhuǎn)Bitmap

Drawable d=xxx; //xxx根據(jù)自己的情況獲取drawable
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bm = bd.getBitmap();
//最終bm就是我們需要的Bitmap對象了。

從資源中獲取Bitmap

public static Bitmap getBitmapFromResources(Activity act, int resId) {
Resources res = act.getResources();
return BitmapFactory.decodeResource(res, resId);
}

byte[] → Bitmap

public static Bitmap convertBytes2Bimap(byte[] b) {
if (b.length == 0) {
return null;
}
return BitmapFactory.decodeByteArray(b, 0, b.length);
}

// Bitmap → byte[]

public static byte[] convertBitmap2Bytes(Bitmap bm) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}

只是很簡單代碼片段,還是很容易懂得

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論

星子县| 韶关市| 河津市| 齐齐哈尔市| 承德县| 玉屏| 乌兰县| 梨树县| 乾安县| 山西省| 开平市| 北流市| 云安县| 浦北县| 通榆县| 迭部县| 新民市| 大埔县| 买车| 阿坝县| 沙田区| 平定县| 分宜县| 禹城市| 孝感市| 高陵县| 肃北| 新田县| 延边| 确山县| 泸水县| 塔城市| 革吉县| 眉山市| 秭归县| 平乐县| 甘谷县| 土默特左旗| 两当县| 靖安县| 客服|