import java.io.File;
import java.io.FileOutputStream;


import android.graphics.Bitmap;
import android.os.Environment;
import android.view.View;


public class TakeScreenShot {


public static String baseDIR= Environment.getExternalStorageDirectory


().getAbsolutePath();
public static String subDIR= "/wan";
public static String SCREEN_SHOTS_LOCATION= baseDIR+subDIR;



public static void takeScreenShot(View view) throws Exception {
takeScreenShot(view, "default");
}


public static void takeScreenShot(View view, String name) throws Exception {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b = view.getDrawingCache();
FileOutputStream fos = null;
try {
File sddir = new File(SCREEN_SHOTS_LOCATION);
if (!sddir.exists()) {
sddir.mkdirs();
}
// fos = new FileOutputStream(SCREEN_SHOTS_LOCATION+name+"_" +


System.currentTimeMillis() + ".jpg");
fos = new FileOutputStream(SCREEN_SHOTS_LOCATION+name + ".jpg");
if (fos != null) {
b.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.close();
}
} catch (Exception e) {
}
}


}


调用:TakeScreenShot.takeScreenShot(solo.getViews().get(0),"WAN22");
takeScreenShot(View view)

更多相关文章

  1. Android每隔一段时间就重复执行指定代码
  2. Android搜索附近的beacon
  3. android SQlite结合SimpleCursorAdapter的简单使用
  4. android JS 互相调用
  5. android休眠与唤醒驱动流程分析
  6. android调用系统通讯录
  7. Timer实现倒计时
  8. android 调用图库并显示选择的图片
  9. Android(安卓)AES加密工具类,解决只能加密不能解密问题

随机推荐

  1. Android的断点设置
  2. android GPS定位 详解(7)
  3. concat_ws, spilt, sort_array,size
  4. Android与H5互调使用cordova的WebView,插
  5. Android 时间获取及格式化
  6. Android进度条、自动提示框、下拉框动态
  7. android studio教程 – 快捷键
  8. android中添加arial字体(非android默认字
  9. Android(安卓)Studio如何设置代码自动提
  10. android 在程序中开启GPS功能