BitmapUtils { public static byte[] bitmapToBytes(Bitmap bitmap) { if (bitmap == null) throw new NullPointerException("bitmap ist null!"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, JPEG_QUALITY, bos); return bos.toByteArray(); } private  BitmapUtils(); static void recycleBitmapFromImageView(ImageView imageView); static void recycleBitmap(Bitmap bitmap); static byte[] bitmapToBytes(Bitmap bitmap);  }
@Test public void testConvertBitmapToBytes(){ Bitmap bitmap = createTestBitmap(); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.CYAN); byte[] bytes = BitmapUtils.bitmapToBytes(bitmap); assertNotNull(bytes); assertTrue(bytes.length > 0); }