title: Android - Real-Time get image data from camera?
body: <p>I want to do some image processing jobs and I want to get real-time image data from my camera(during preview state) instead of after taking pictures.</p>
  
  <p>I looked on this <a href="https://stackoverflow.com/questions/20097698/getting-image-data-continuously-from-camera-surfaceview-or-surfaceholder?newreg=4eb6d0ee3b434975bd1512ad72657b90">post</a> but don't know how to use this. </p>
  
  <p>After setting this,</p>
  
  <pre><code>SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback() 
  {   
      public void surfaceCreated(SurfaceHolder holder) {
         camera.setPreviewCallback(previewCallback);
      }
  }
  </code></pre>
  
  <p>and this </p>
  
  <pre><code>private Camera.PreviewCallback  previewCallback= new Camera.PreviewCallback()
  {   
      @Override
      public void onPreviewFrame(byte[] data,Camera cam)
      {
              Camera.Size previewSize = cam.getParameters().getPreviewSize();
              YuvImage yuvImage = new YuvImage(data, ImageFormat.NV21,previewSize.width,previewSize.height, null);
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              yuvImage.compressToJpeg(new Rect(0,0,previewSize.width,previewSize.height),80,baos);
              byte[] jdata = baos.toByteArray();
              Bitmap bitmap = BitmapFactory.decodeByteArray(jdata,0,jdata.length);    
      }
  };
  </code></pre>
  
  <p>How can I real-time get my image data? Could anyone please kindly give me an short example code?</p>
  
  <p>Thanks</p>