title: Android: Accessing hardware camera preview frame data without drawing them
body: <p>According to the android camera docs from the Java SDK side, the camera preview frames have to be supplied a (visible and active) surface to be drawn to in order to access the frame data. I have linked a few of the things I have come across here (I'm new so capped at 2 hyperlinks), but I went over tons of documentation of various things before winding up posting my own question here on SO.</p>
  <h3>My Problems:</h3>
  <p>a) I explicitly don't want to draw the camera preview to the screen, I just want the byte data (which I can get from here) straight from the camera buffer if possible.</p>
  <p>b) Yes, I saw this:
  <a href="https://stackoverflow.com/questions/2386025/android-camera-without-preview">Taking picture from camera without preview</a>.</p>
  <p>However, this dictates that apps using this library have to insert this (seemingly) arbitrary view into their app layout, which has to be visible all the time (they can't switch layouts, change visibility of parent containers or use a subactivity) during app life-cycle.</p>
  <p>In fact, my needs are similar to <a href="https://stackoverflow.com/questions/9744790/android-possible-to-camera-capture-without-a-preview">this poster's</a>, except I want continuous real-time stream of the camera preview data, not a capture saved to image on disk. Hence <code>PictureCallback</code> works for him together with the <code>myCamera.takePicture</code> call. For obvious reasons, writing continuous captures to disk is not a solution for me, so that won't work in my case. <code>myCamera.takePicture</code> is also much slower than getting the preview frames.</p>
  <p>c) I have started dabbling with the NDK, and have gotten a pretty good feel for it. However, according to <a href="https://groups.google.com/forum/?fromgroups#!topic/android-ndk/qehnrEEoxa0%5B1-25%5D" rel="noreferrer">this</a> accessing camera data via native is just not supported or recommended, and a huge hassle for device compatibility even then.</p>
  <p>If this is outdated, and there are solid NDK routes to acquiring camera data from android devices, I couldn't find them, so if you could point them out to me that would be great.</p>
  <p>d) I want to make this library accessible from tools like Unity (in the form of a unity plugin), for which I want to be able to just compile it into a JAR (or .so for native) and expect it to work on android apps that import the library that way so that they can use the camera without specific UI/layout configurations needed from the app developer.</p>
  <h3>Context:</h3>
  <p>I want to be able to create a vision-processing library for use in android apps, and don't want to limit the apps using the library to have to use specific app layouts and draw specific views to the screen in order to use the vision processing results - for a very simple example, if an app wants to use my library to get the average color of what the camera sees, and wants to tint an image on the screen that color.</p>
  <p>Whatever suggestions I can get towards any of the points I have will be super-helpful. Thanks a lot for your time!</p>