关闭

Android 一种截图方法,稍微修改.保存

标签: Android截图
162人阅读 评论(0) 收藏 举报
分类:

截图方法 :

protected void GetandSaveCurrentImage() {

WindowManager widowManager = getWindowManager();
Display display = widowManager.getDefaultDisplay();
int w = display.getWidth();
int h = display.getHeight();


Bitmap Bmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);
View decorview = this.getWindow().getDecorView();
decorview.setDrawingCacheEnabled(true);
Bmp = decorview.getDrawingCache();
try {
String SavePath = getSDCardPath() + "/ScreenImage";
File path = new File(SavePath);
long currenttime = System.currentTimeMillis();
String filepath = SavePath +File.separator+ currenttime+".jpg";
File file = new File(filepath);
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, 90, fos);
fos.flush();
fos.close();
Log.i("LW", "截屏文件已保存至SDCard/ScreenImage/下");
}
} catch (Exception e) {
e.printStackTrace();
}
}

private String getSDCardPath() {
File sdCardDir = null;
boolean sdcardExit = Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
if (sdcardExit) {
sdCardDir = Environment.getExternalStorageDirectory();
}
return sdCardDir.toString();
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场