Android How to - Convert a byte array to a bitmap








Question

We would like to know how to convert a byte array to a bitmap.

Answer

We can create a Bitmap from an array of bytes by using the BitmapFactory decodeByteArray method..

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
/*  w ww .ja  v  a2s . c om*/
public class Main {

    /**
     * This is a convenience method for converting a byte array to a bitmap
     */
    public static Bitmap convertBytesToBitmap(byte[] image) {
        return BitmapFactory.decodeByteArray(image, 0, image.length);
    }

}