Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import java.io.ByteArrayOutputStream; public class Main { public static byte[] drawable2Bytes(Drawable drawable, Bitmap.CompressFormat format) { return drawable == null ? null : bitmap2Bytes(drawable2Bitmap(drawable), format); } public static byte[] bitmap2Bytes(Bitmap bitmap, Bitmap.CompressFormat format) { if (bitmap == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(format, 100, baos); return baos.toByteArray(); } public static Bitmap drawable2Bitmap(Drawable drawable) { return drawable == null ? null : ((BitmapDrawable) drawable).getBitmap(); } }