截屏一种方式



?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//这种方法状态栏是空白,显示不了状态栏的信息
private void saveCurrentImage() 
     //获取当前屏幕的大小
     int width = getWindow().getDecorView().getRootView().getWidth();
     int height = getWindow().getDecorView().getRootView().getHeight();
     //生成相同大小的图片
     Bitmap temBitmap = Bitmap.createBitmap( width, height, Config.ARGB_8888 );   
     //找到当前页面的跟布局
     View view =  getWindow().getDecorView().getRootView();
     //设置缓存
     view.setDrawingCacheEnabled( true );
     view.buildDrawingCache();
     //从缓存中获取当前屏幕的图片
     temBitmap = view.getDrawingCache();
 
     //输出到sd卡
     if (FileIOUtil.getExistStorage()) {
         FileIOUtil.GetInstance().onFolderAnalysis(FileIOUtil.GetInstance().getFilePathAndName());
         File file = new File(FileIOUtil.GetInstance().getFilePathAndName()); 
         try {
             if (!file.exists()) { 
                 file.createNewFile(); 
             }
             FileOutputStream foStream = new FileOutputStream(file);
             temBitmap.compress(Bitmap.CompressFormat.PNG, 100 , foStream);
             foStream.flush(); 
             foStream.close();
         } catch (Exception e) {
             Log.i( "Show" , e.toString());
         }
     }
}

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//这种方法状态栏是空白,显示不了状态栏的信息
private void saveCurrentImage() 
     //获取当前屏幕的大小
     int width = getWindow().getDecorView().getRootView().getWidth();
     int height = getWindow().getDecorView().getRootView().getHeight();
     //生成相同大小的图片
     Bitmap temBitmap = Bitmap.createBitmap( width, height, Config.ARGB_8888 );   
     //找到当前页面的跟布局
     View view =  getWindow().getDecorView().getRootView();
     //设置缓存
     view.setDrawingCacheEnabled( true );
     view.buildDrawingCache();
     //从缓存中获取当前屏幕的图片
     temBitmap = view.getDrawingCache();
 
     //输出到sd卡
     if (FileIOUtil.getExistStorage()) {
         FileIOUtil.GetInstance().onFolderAnalysis(FileIOUtil.GetInstance().getFilePathAndName());
         File file = new File(FileIOUtil.GetInstance().getFilePathAndName()); 
         try {
             if (!file.exists()) { 
                 file.createNewFile(); 
             }
             FileOutputStream foStream = new FileOutputStream(file);
             temBitmap.compress(Bitmap.CompressFormat.PNG, 100 , foStream);
             foStream.flush(); 
             foStream.close();
         } catch (Exception e) {
             Log.i( "Show" , e.toString());
         }
     }
}


       
       
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//这种方法状态栏是空白,显示不了状态栏的信息
private void saveCurrentImage() 
     //获取当前屏幕的大小
     int width = getWindow().getDecorView().getRootView().getWidth();
     int height = getWindow().getDecorView().getRootView().getHeight();
     //生成相同大小的图片
     Bitmap temBitmap = Bitmap.createBitmap( width, height, Config.ARGB_8888 );   
     //找到当前页面的跟布局
     View view =  getWindow().getDecorView().getRootView();
     //设置缓存
     view.setDrawingCacheEnabled( true );
     view.buildDrawingCache();
     //从缓存中获取当前屏幕的图片
     temBitmap = view.getDrawingCache();
 
     //输出到sd卡
     if (FileIOUtil.getExistStorage()) {
         FileIOUtil.GetInstance().onFolderAnalysis(FileIOUtil.GetInstance().getFilePathAndName());
         File file = new File(FileIOUtil.GetInstance().getFilePathAndName()); 
         try {
             if (!file.exists()) { 
                 file.createNewFile(); 
             }
             FileOutputStream foStream = new FileOutputStream(file);
             temBitmap.compress(Bitmap.CompressFormat.PNG, 100 , foStream);
             foStream.flush(); 
             foStream.close();
         } catch (Exception e) {
             Log.i( "Show" , e.toString());
         }
     }
}
	returnBack.setVisibility(View.INVISIBLE);
//        saveCurrentImage();
//        saveCurrentImage1();
        View userLayout = findViewById(R.id.user_layout);
//下面两行打开有时候会造成UI移位
//        userLayout.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
//        userLayout.layout(0, 0, userLayout.getMeasuredWidth(), userLayout.getMeasuredHeight());
        userLayout.buildDrawingCache();
        Bitmap shareImage = userLayout.getDrawingCache();
        returnBack.setVisibility(View.VISIBLE);

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//这种方法状态栏是空白,显示不了状态栏的信息
private void saveCurrentImage() 
     //获取当前屏幕的大小
     int width = getWindow().getDecorView().getRootView().getWidth();
     int height = getWindow().getDecorView().getRootView().getHeight();
     //生成相同大小的图片
     Bitmap temBitmap = Bitmap.createBitmap( width, height, Config.ARGB_8888 );   
     //找到当前页面的跟布局
     View view =  getWindow().getDecorView().getRootView();
     //设置缓存
     view.setDrawingCacheEnabled( true );
     view.buildDrawingCache();
     //从缓存中获取当前屏幕的图片
     temBitmap = view.getDrawingCache();
 
     //输出到sd卡
     if (FileIOUtil.getExistStorage()) {
         FileIOUtil.GetInstance().onFolderAnalysis(FileIOUtil.GetInstance().getFilePathAndName());
         File file = new File(FileIOUtil.GetInstance().getFilePathAndName()); 
         try {
             if (!file.exists()) { 
                 file.createNewFile(); 
             }
             FileOutputStream foStream = new FileOutputStream(file);
             temBitmap.compress(Bitmap.CompressFormat.PNG, 100 , foStream);
             foStream.flush(); 
             foStream.close();
         } catch (Exception e) {
             Log.i( "Show" , e.toString());
         }
     }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值