drawable 转换成bitmap
public Bitmap setIcon(Drawable drawable) { int width = drawable.getIntrinsicWidth(); // 取drawable的长宽 int height = drawable.getIntrinsicHeight(); Log.v("setIcon","*****width:" + width); Log.v("setIcon","*****height:" + height); Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565; // 取drawable的颜色格式 int ww = (int)(width*1.5); int hh = (int)(height*1.5); Bitmap bitmap = Bitmap.createBitmap(ww, hh, config); // 建立对应bitmap Canvas canvas = new Canvas(bitmap); // 建立对应bitmap的画布 drawable.setBounds(0, 0, ww, hh); drawable.draw(canvas); // 把drawable内容画到画布中 return bitmap; }
相关推荐
songfens 2020-01-10
MIKUScallion 2020-01-10
博了个客 2020-05-31
lixiaotao 2020-03-05
调调 2013-07-24
83580494 2013-06-29
TongsengsBlog 2013-08-27
Android进阶 2013-08-25
89143951 2011-08-25
八角塘塘主 2019-10-29
lerayZhang 2015-01-11
timewind 2019-07-01
Ashes 2019-06-30
learningITwell 2019-06-28
PGzxc 2019-06-28
xusong 2012-08-01
Android进阶 2019-06-27
helowken 2019-06-21
飞奔的熊猫 2019-06-21