Java tutorial
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.File; import android.graphics.Bitmap; import android.graphics.BitmapFactory; public class Main { public static byte[] bitmapToByte(Bitmap bitmap) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos); return bos.toByteArray(); } public static byte[] bitmapToByte(String path) { File file = new File(path); if (!file.exists()) { return null; } Bitmap bitmap = BitmapFactory.decodeFile(path); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos); return bos.toByteArray(); } }