Convert bitmap To Byte Array - Android android.graphics

Android examples for android.graphics:Bitmap Convert

Description

Convert bitmap To Byte Array

Demo Code

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;

public class Main {

  public static byte[] bitmapToByteArray(Bitmap bitmap) throws IOException {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] array = stream.toByteArray();
    stream.close();//ww w .ja v  a2 s.  c  om
    return array;

  }

}

Related Tutorials