Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import android.graphics.Bitmap; public class Main { public static byte[] compressBitmap(Bitmap bitmap) { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); if (bitmap.compress(Bitmap.CompressFormat.JPEG, 80, byteStream)) { try { byteStream.flush(); byteStream.close(); } catch (IOException ex) { ex.printStackTrace(); } } return byteStream.toByteArray(); } }