title: Processing Android camera frames in real time
body: <p>I'm trying to create an Android application that will process camera frames in real time. To start off with, I just want to display a grayscale version of what the camera sees. I've managed to extract the appropriate values from the byte array in the <code>onPreviewFrame</code> method. Below is just a snippet of my code:</p>
  
  <pre><code>byte[] pic;
  int pic_size;
  Bitmap picframe;
  public void onPreviewFrame(byte[] frame, Camera c)
  {
      pic_size = mCamera.getParameters().getPreviewSize().height * mCamera.getParameters().getPreviewSize().width;
      pic = new byte[pic_size];
      for(int i = 0; i &lt; pic_size; i++)
      {
          pic[i] = frame[i];
      }
      picframe = BitmapFactory.decodeByteArray(pic, 0, pic_size);
  }
  </code></pre>
  
  <p>The first <code>[width*height]</code> values of the <code>byte[]</code> frame array are the luminance (greyscale) values. Once I've extracted them, how do I display them on the screen as an image? Its not a 2D array as well, so how would I specify the width and height?</p>