/**
* 获取和保存当前屏幕的截图
*/
public static void SaveCurrentImage(Activity ac)
{
//创建Bitmap
WindowManager windowManager = ac.getWindowManager();
Display display = windowManager.getDefaultDisplay();
int w = display.getWidth();
int h = display.getHeight();
Bitmap bmp = Bitmap.createBitmap( w, h, Config.ARGB_8888 );
//获取屏幕
View decorview = ac.getWindow().getDecorView();
decorview.setDrawingCacheEnabled(true);
bmp = decorview.getDrawingCache();
String SavePath = getSDCardPath()+"/ScreenImage";
//存储为Bitmap
try {
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd_HH-mm-ss", Locale.CHINA);
File path = new File(SavePath);
//文件
jdConstants.FILESAVEPATH = SavePath + "/"+sdf.format(new Date()) + ".png";
File file = new File(jdConstants.FILESAVEPATH);
if(!path.exists()){
path.mkdirs();
}
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fos = null;
fos = new FileOutputStream(file);
if (null != fos) {
bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
* 获取和保存当前屏幕的截图
*/
public static void SaveCurrentImage(Activity ac)
{
//创建Bitmap
WindowManager windowManager = ac.getWindowManager();
Display display = windowManager.getDefaultDisplay();
int w = display.getWidth();
int h = display.getHeight();
Bitmap bmp = Bitmap.createBitmap( w, h, Config.ARGB_8888 );
//获取屏幕
View decorview = ac.getWindow().getDecorView();
decorview.setDrawingCacheEnabled(true);
bmp = decorview.getDrawingCache();
String SavePath = getSDCardPath()+"/ScreenImage";
//存储为Bitmap
try {
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd_HH-mm-ss", Locale.CHINA);
File path = new File(SavePath);
//文件
jdConstants.FILESAVEPATH = SavePath + "/"+sdf.format(new Date()) + ".png";
File file = new File(jdConstants.FILESAVEPATH);
if(!path.exists()){
path.mkdirs();
}
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fos = null;
fos = new FileOutputStream(file);
if (null != fos) {
bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}

被折叠的 条评论
为什么被折叠?



