Android examples for android.graphics.drawable:Drawable
Retrieves byte data associated with the given Drawable
import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import java.io.ByteArrayOutputStream; public class Main{ /**//from w w w. j a v a2 s . c om * Retrieves byte data associated with the given {@link Drawable} * * @param drawable * The {@link Drawable} instance * @return byte data which represents the {@link Drawable} */ public static byte[] getImageByteData(final Drawable drawable) { Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); return stream.toByteArray(); } }