public static Bitmap DrawableToBitmap(Drawable drawable) { // 获取 drawable 长宽 int width = drawable.getIntrinsicWidth(); int heigh = drawable.getIntrinsicHeight(); drawable.setBounds(0, 0, width, heigh); // 获取drawable的颜色格式 Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; // 创建bitmap Bitmap bitmap = Bitmap.createBitmap(width, heigh, config); // 创建bitmap画布 Canvas canvas = new Canvas(bitmap); // 将drawable 内容画到画布中 drawable.draw(canvas); return bitmap; }