Take screenshot of chart in android


#1

Is there a way to programatically take a screenshot of the chart in android? 

I have this code that saves an image of the chart but the data doesn´t appear.
I think I am missing to add the opengl data of the chart to the image but I don´t know how. 

public void takeChartScreenshot() {
  //Obtain bitmap of chart view
  View rootView = getActivity().findViewById(R.id.chart);
  rootView.setDrawingCacheEnabled(true);
  Bitmap image = rootView.getDrawingCache();

  //Save image in Camera folder
  File imagePath = new File(Environment.getExternalStorageDirectory() +
  File.separator+android.os.Environment.DIRECTORY_DCIM +
  "/Camera/screenshot.png");
   try {
     FileOutputStream fos = new FileOutputStream(imagePath);
     image.compress(CompressFormat.JPEG, 100, fos);
     fos.flush();
     fos.close();
     Toast.makeText(getActivity(), "Image saved in " + 
     imagePath.getAbsolutePath() , Toast.LENGTH_LONG).show();
  } catch (FileNotFoundException e) {
     Log.e("GREC", e.getMessage(), e);
  } catch (IOException e) {
     Log.e("GREC", e.getMessage(), e);
  }
}

Thanks.
 


#2

Hi Garza,

As you suggest, it is the OpenGL part of the image that is missing. Unfortunately, however, we don’t yet have a screenshot feature in the Android version, but it is on our roadmap and we will be looking at this in due course. 

Best regards,

Robin Sillem