如何在android中使用androidplot绘制图形的屏幕截图?

问题描述:

我正在试图在Android中绘制使用Androidplots绘制的截图。我怎样才能截图使用Androidplot编程的盆栽图?如何在android中使用androidplot绘制图形的屏幕截图?

您可以使用这样一个方法:

@SuppressLint("SimpleDateFormat") 
protected final void shoot(final Context ctx, final View v, final String prefix) 
{ 

    // Get the bitmap from the view 
    v.setDrawingCacheEnabled(true); 
    final Bitmap bmp = v.getDrawingCache(); 

    final SimpleDateFormat sdf = new SimpleDateFormat("[email protected]"); 
    final Calendar cal = Calendar.getInstance(); 

    // Set file properties 
    fileJPG = prefix + "_" + sdf.format(cal.getTime()); 

    /* 
    Create a path where we will place our picture in the user's public 
    pictures directory. Note that you should be careful about what you 
    place here, since the user often manages these files. 
    For pictures and other media owned by the application, consider 
    Context.getExternalMediaDir(). 
    */ 
    final File path = 
     Environment.getExternalStoragePublicDirectory 
     (
      //Environment.DIRECTORY_PICTURES 
      //Environment.DIRECTORY_DCIM 
      Environment.DIRECTORY_DCIM + "/SomePath/" 
     ); 

    // Make sure the Pictures directory exists. 
    if(!path.exists()) 
    { 
     path.mkdirs(); 
    } 

    final File file = new File(path, fileJPG + ".jpg"); 

    try 
    { 
     final FileOutputStream fos = new FileOutputStream(file); 
     final BufferedOutputStream bos = new BufferedOutputStream(fos, 8192); 

     bmp.compress(CompressFormat.JPEG, 85, bos); 

     bos.flush(); 
     bos.close(); 

     fileJPG = file.getPath(); 
    } 
    catch (final IOException e) 
    { 
     e.printStackTrace(); 
    } 
} 

注意,你可以把你的APP的截图只,而不是背后是什么,即使它是半透明的。

+0

感谢它在绘制图之前工作,但在绘制图之后它给出了空指针异常并崩溃请帮助..... – Babith 2014-10-20 11:30:46

+0

我正在使用它与aChartEngine。它在绘制之后保存图形:我首先在创建片段时绘制图形,然后通过长时间点击我截取屏幕截图。 – 2014-10-20 11:52:23