Android How to - Convert byte array to Bitmap








Question

We would like to know how to convert byte array to Bitmap.

Answer

The BitmapFactory can create a Bitmap from an array of byte.

/*from   ww  w  .  j a v  a 2  s  .  c  o m*/
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {
    public static Bitmap Bytes2Bimap(byte[] b) {
      
  if (b.length == 0) {
      return null;
  }
  return BitmapFactory.decodeByteArray(b, 0, b.length);  
    }
}