title: Android: how to display camera preview with callback?
body: <p>What I need to do is quite simple, I want to manually display preview from camera using camera callback and I want to get at least 15fps on a real device. I don't even need the colors, I just need to preview grayscale image.
  Images from camera are in YUV format and you have to process it somehow, which is the main performance problem. I'm using API 8.</p>
  
  <p>In all cases I'm using camera.setPreviewCallbackWithBuffer(), that is faster than camera.setPreviewCallback(). It seems that I cant get about 24 fps here, if I'm not displaying the preview. So there is not the problem.</p>
  
  <p>I have tried these solutions:</p>
  
  <p><strong>1. Display camera preview on a SurfaceView as a Bitmap.</strong> It works, but the performance is about 6fps.</p>
  
  <pre><code>baos = new ByteOutputStream();
  yuvimage=new YuvImage(cameraFrame, ImageFormat.NV21, prevX, prevY, null);
  
  yuvimage.compressToJpeg(new Rect(0, 0, prevX, prevY), 80, baos);
  jdata = baos.toByteArray();
  
  bmp = BitmapFactory.decodeByteArray(jdata, 0, jdata.length); // Convert to Bitmap, this is the main issue, it takes a lot of time
  
  canvas.drawBitmap(bmp , 0, 0, paint);
  </code></pre>
  
  <p><hr/></p>
  
  <p><strong>2. Display camera preview on a GLSurfaceView as a texture.</strong> Here I was displaying only luminance data (greyscale image), which is quite easy, it requires only one arraycopy() on each frame. I can get about 12fps, but I need to apply some filters to the preview and it seems, that it can't be done fast in OpenGL ES 1. So I can't use this solution. Some details of this in <a href="https://stackoverflow.com/questions/8198455/adjusting-contrast-of-a-texture-in-opengl-es">another question</a>.
  <hr/></p>
  
  <p><strong>3. Display camera preview on a (GL)SurfaceView using NDK</strong> to process the YUV data. I find a solution <a href="http://nhenze.net/?p=253" rel="nofollow noreferrer">here</a> that uses some C function and NDK. But I didn't manage to use it, <a href="https://stackoverflow.com/questions/8303370/how-to-use-c-function-on-android-with-ndk">here some more details</a>. But anyway, this solution is done to return ByteBuffer to display it as a texture in OpenGL and it won't be faster than the previous attempt. So I would have to modify it to return int[] array, that can be drawn with canvas.drawBitmap(), but I don't understand C enough to do this.
  <hr/></p>
  
  <p>So, is there any other way that I'm missing or some improvement to the attempts I tried?</p>