Android截图,截取不到AlertDialog?
阿神
阿神 2017-04-18 09:05:42
0
2
472
private void screenshot1(String Strname)
   {
       /**
        * Strname--如  2.png  需要带后缀
        * */
       // 获取屏幕
       View dView = getWindow().getDecorView();
       dView.setDrawingCacheEnabled(true);
       dView.buildDrawingCache();
       Bitmap bmp = dView.getDrawingCache();
       if (bmp != null)
       {
           try {
               // 获取内置SD卡路径
               String sdCardPath = Environment.getExternalStorageDirectory().getPath();
               // 图片文件路径
 
               File filedir = new File(sdCardPath + File.separator + "AA");  // 这里的AA为创建的AA文件夹,在根目录下
               if (!filedir.exists()) {
                   filedir.mkdirs();
               }
               File saveFile = new File(filedir, Strname);  
               FileOutputStream outStream1 = new         FileOutputStream(saveFile);
               System.out.println(outStream1.toString());
               ByteArrayOutputStream stream = new ByteArrayOutputStream();
               bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
               byte[] byteArray = stream.toByteArray();
               outStream1.write(byteArray);
               outStream1.close();
               Toast.makeText(Zhuye_Activity.this,"截图保存成功",Toast.LENGTH_SHORT).show();
               dView.setDrawingCacheEnabled(false);  // 这里不设置false,那么下次截图还是上次的图片
           } catch (Exception e) {
           }
       }
   }

这个方不行……谁有解决方法?

阿神
阿神

闭关修行中......

reply all(2)
伊谢尔伦

For dialog, you can only capture the dialog view once more and then superimpose it on the activity view bitmap for output.

小葫芦

github portal: jraska/Falcon: Take Android screenshots with Falcons bright eye!

p.s. This solution is not perfect, the bottom navigation button does not cut into the image.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template