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());
}
}
}
|