andorid绘图公共函数:
/**
* author:beef
* email :460955584@qq.com
* created 2016/11/8 0:45
* @param resources 资源id.
* @param context 上下文.
* 依赖drawableToBitamp函数。
*/
public Bitmap createBitmap(int resources,Context context) {
final Drawable drawable = ContextCompat.getDrawable(context, resources);
final Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(wrappedDrawable, getCurrentHintTextColor());
return drawableToBitamp(wrappedDrawable);
}
/**
* author:beef
* email :460955584@qq.com
* created 2016/11/8 0:47
* @param drawable 需要变换的Drawable
*/
private Bitmap drawableToBitamp(Drawable drawable)
{
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
drawable.draw(canvas);
return bitmap;
}