参考:
http://www.it1352.com/902089.html
//将drawable转换为位图
public static Bitmap drawableToBitmap(Drawable drawable){
Bitmap bitmap = null;
if(drawable instanceof BitmapDrawable){
BitmapDrawable bitmapDrawable =(BitmapDrawable)drawable;
if(bitmapDrawable.getBitmap()!= null){
return bitmapDrawable.getBitmap();
}
}
if(drawable.getIntrinsicWidth()<= 0 || drawable.getIntrinsicHeight()<= 0){
bitmap = Bitmap.createBitmap(1,1,Bitmap.Config.ARGB_8888); //单色位图将创建1x1像素
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight(),Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0,0,canvas.getWidth(),canvas.getHeight());
drawable.draw(canvas);
//返回位图;
return bitmap;
}
将原来的
位图b =((BitmapDrawable)drawable).getBitmap();
替换为
Bitmap b = drawableToBitmap(drawable);//这句是修改后的
在这个的上面一句
Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
在xml布局直接引用
<com.study.brocast_demo_self.ui.RoundImageView
android:layout_width="@dimen/widget_size_50"
android:layout_height="@dimen/widget_size_50"
android:layout_marginLeft="@dimen/widget_size_15"
imagecontrol:border_inside_color="#bc0978"
imagecontrol:border_outside_color="#ba3456"
imagecontrol:border_thickness=“1dp”/>