现在的位置: 首页 > 综合 > 正文

android 随手记 截图

2018年09月15日 ⁄ 综合 ⁄ 共 1408字 ⁄ 字号 评论关闭


  1.     
    http://s.click.taobao.com/t?e=zGU34CA7K%2BPkqB07S4%2FK0CFcRfH0GoT805sipKkIVZQ0uuEjPqv8MWgjpxGsutM546MultASUypwQss%2B58Tq%2B6tSAXI0RdXt7dWGt8peNzSslA%3D%3D



  2. private void GetandSaveCurrentImage()  
  3. {  
  4.     //1.构建Bitmap  
  5.     WindowManager windowManager = getWindowManager();  
  6.     Display display = windowManager.getDefaultDisplay();  
  7.     int w = display.getWidth();  
  8.     int h = display.getHeight();  
  9.       
  10.     Bitmap Bmp = Bitmap.createBitmap( w, h, Config.ARGB_8888 );      
  11.       
  12.     //2.获取屏幕  
  13.     View decorview = this.getWindow().getDecorView();   
  14.     decorview.setDrawingCacheEnabled(true);   
  15.     Bmp = decorview.getDrawingCache();   
  16.   
  17.     //3.保存Bitmap   
  18.     try {  
  19.         File path = new File(SavePATH);  
  20.         //文件  
  21.         String filepath = SavePATH + "/Screen_1.png";  
  22.         File file = new File(filepath);  
  23.         if(!path.exists()){  
  24.             path.mkdirs();  
  25.         }  
  26.         if (!file.exists()) {  
  27.             file.createNewFile();  
  28.         }  
  29.           
  30.         FileOutputStream fos = null;  
  31.         fos = new FileOutputStream(file);  
  32.         if (null != fos) {  
  33.             Bmp.compress(Bitmap.CompressFormat.PNG, 90, fos);  
  34.             fos.flush();  
  35.             fos.close();    
  36.               
  37.             Toast.makeText(SiteMap.this"截屏文件已保存至SDCard/ADASiteMaps/ScreenImage/下", Toast.LENGTH_LONG).show();  
  38.         }  
  39.   
  40.     } catch (Exception e) {  
  41.         e.printStackTrace();  
  42.     }  

抱歉!评论已关闭.