public static byte[] drawableToByteArray(Drawable d, boolean resize) {
        Bitmap bitmap = ((BitmapDrawable) d).getBitmap();

        if (resize) bitmap = Bitmap.createScaledBitmap(bitmap, 32, 32, false);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        return stream.toByteArray();
    }
Created by guohao4 on 2017/10/24.
Email: Tornaco@163.com
android/modules/module_common/src/main/java/github/tornaco/android/thanos/util/BitmapUtil.java