title: Retrieve data from raw image taken with camera2API
body: <p>I have used the <a href="https://github.com/googlesamples/android-Camera2Raw" rel="nofollow noreferrer">official sample</a> for using the Camera2 API to capture a RAW sensor frame. The code is in java but I transformed it to Kotlin with the help of Android Studio. I tested it, and I'm capable of taking and saving a dng picture to my phone. Not a problem so far.</p>
  
  <p>But what I really want is to be able to retrieve some information about the picture, I don't care about saving it. I want to do the processing directly with my smartphone. </p>
  
  <p>What I tried so far, is to get the byte array of the image.
  In the function <code>dequeueAndSaveImage</code>, I retrieve the image from a ImageReader : <code>image = reader.get()!!.acquireNextImage()</code>.
  I suppose that is here that I have to process the image. I tried to log the <code>image.width</code>, <code>image.height</code> and the <code>image.planes.count</code> and there was no problem.
  By the way, since the format is <code>RAW_SENSOR</code>, the <code>image.planes.count</code> is 1, corresponding to <a href="https://developer.android.com/reference/kotlin/android/media/Image?hl=en#getplanes" rel="nofollow noreferrer">a single plane of raw sensor image data, with 16 bits per color sample.</a></p>
  
  <p>But when I'm trying to log the <code>image.planes[0].buffer.array().size</code> for example, I'm getting a <code>FATAL EXCEPTION: CameraBackground</code> with <code>java.lang.UnsupportedOperationException</code>. </p>
  
  <p>And if I'm trying to log the same thing, but in the function that saves the image to a dng file, I'm getting another type of error : <code>FATAL EXCEPTION: AsyncTask #1</code> with <code>java.lang.UnsupportedOperationException</code></p>
  
  <p>Am I even going the right way in order to retrieve information about the image? For example the the intensity of the pixels, the average, the standard deviation for each channel of color, etc...</p>
  
  <p>EDIT : I think that I found the problem, although not the solution.
  When I log <code>image.planes[0].buffer.hasArray()</code>, it returns false, that's why calling <code>array()</code> throws an exception.</p>
  
  <p>But then, how do I get the data from the image?</p>