Bitmap和Drawble在图像处理和自定义View的时候经常使用到,然而,我们经常会遇到需要将Bitmap和Drawble之间进行转换,使用如下的函数就可以方便的转换了
private Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { BitmapDrawable bd = (BitmapDrawable) drawable; return bd.getBitmap(); } int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); Bitmap bm = Bitmap.createBitmap(w,h,