Search code examples
androidimagebitmapfactory

Byte array to image in Android


I have a linear byte array whose values I want to set as pixels of an image. The byte array length is 4800 and I want it to be displayed as a 80x60 image with pixel values set row-wise one after the other. I know that BitmapFactory helps to handle such tasks but how do I specify the height and width of the image?


Solution

  • It sounds like what you've got is a byte array with the colors for the pixels in a Bitmap. If so, you will probably want to use the setPixels() method:

    Bitmap bmp = Bitmap.createBitmap(80, 60, myConfig);
    
    bmp.setPixels(myPixelData, 0, 80, 0, 0, 80, 60);