title: Taking screenshot programmatically doesnt capture the contents of surfaceVIew
body: <p>I have an app that I want to be able to capture a screenshot. The background of the layout is a surfaceView that shows video from the rear camera. The following code is able to take a screenshot but the contents of the surfaceView is saved as black.   Here is the code :</p>
  
  <pre><code>btn.setOnClickListener(new OnClickListener()
  {
  
  public void onClick(View v)
  {
      Random num = new Random();
      int nu=num.nextInt(1000);
      Bitmap bmp;
      CamView.setDrawingCacheEnabled(true); 
      CamView.buildDrawingCache(true);
      Bitmap bmp2 = Bitmap.createBitmap(CamView.getDrawingCache()); //Screenshot of the layout
      CamView.setDrawingCacheEnabled(false);
  
      SurView.setDrawingCacheEnabled(true); 
      SurView.buildDrawingCache(true);
      Bitmap bmp1 = Bitmap.createBitmap(SurView.getDrawingCache()); //Screenshot of the surfaceView
      SurView.setDrawingCacheEnabled(false);
  
      Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(),bmp1.getConfig());
      Canvas canvas = new Canvas(bmOverlay); //Overlaying the 2 bitmaps
      canvas.drawBitmap(bmp1, 0,0, null);
      canvas.drawBitmap(bmp2, 0,0, null);
      bmp=bmOverlay;
  
      //saving the file
      ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
      bmp.compress(CompressFormat.JPEG, 100, bos); 
      byte[] bitmapdata = bos.toByteArray();
      ByteArrayInputStream fis = new ByteArrayInputStream(bitmapdata);
  
      String picId=String.valueOf(nu);
      String myfile="Ghost"+picId+".jpeg";
  
      File dir_image = new  File(Environment.getExternalStorageDirectory()+
              File.separator+"Ultimate Entity Detector");
      dir_image.mkdirs();
  
      try {
          File tmpFile = new File(dir_image,myfile); 
          FileOutputStream fos = new FileOutputStream(tmpFile);
  
           byte[] buf = new byte[1024];
              int len;
              while ((len = fis.read(buf)) &gt; 0) {
                  fos.write(buf, 0, len);
              }
                  fis.close();
                  fos.close();
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  });
  </code></pre>
  
  <p>I updated the code. Now i create 2 bitmaps, 1 for the layout xml and 1 for the surfaceView and then i overlay them into a single bitmap. But the surfaceView bitmap is still black</p>