title: Save a captured image
body: <p>I have this piece of code (Just for experimenting) :</p>
  
  <pre><code>public void captureFromCam(View v) throws CameraAccessException {
      try {
          cm.openCamera("0", new CameraDevice.StateCallback(){
              @Override
              public void onClosed(CameraDevice camera) {
                  super.onClosed(camera);
              }
  
              @Override
              public void onError(CameraDevice camera, int error) {
  
              }
  
              @Override
              public void onOpened(final CameraDevice cam) {
                  Log.d("CameraApp", "Camera Opened");
                  ImageReader ir = ImageReader.newInstance(800, 600, 256, 1);
                  Surface surface = ir.getSurface();
                  final ArrayList&lt;Surface&gt; l = new ArrayList();
                  l.add(surface);
                  try {
                      cam.createCaptureSession(l, new CameraCaptureSession.StateCallback() {
                          @Override
                          public void onConfigured(CameraCaptureSession session) {
                              Log.e("CameraApp", "Configured");
                              CaptureRequest.Builder builder = null, b2;
                              try {
                                  builder = cam.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
                              } catch (CameraAccessException e) {
                                  e.printStackTrace();
                              }
                              builder.addTarget(l.get(0));
                              CaptureRequest request = builder.build();
                              try {
                                  session.capture(request, new CameraCaptureSession.CaptureCallback() {
                                      @Override
                                      public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
                                          Log.e("CameraApp", "Captured");
                                      }
                                  }, null);
                              } catch (CameraAccessException e) {
                                  e.printStackTrace();
                              }
                          }
  
                          @Override
                          public void onConfigureFailed(CameraCaptureSession session) {
  
                          }
                      }, null);
                  } catch (CameraAccessException e) {
                      e.printStackTrace();
                  }
  
              }
  
              @Override
              public void onDisconnected(CameraDevice camera) {
  
              }
          }, null);
      } catch (CameraAccessException e) {
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>The interesting part is <code>onCaptureCompleted</code>, as I understood result is somehow my picture.</p>
  
  <p>How do I save this picture to a file? or if it is not my picture, where is my picture and how to I save it to file?</p>
  
  <p>I am aware this question was answered but this is API 21 and it very different from the old one.</p>