/**
* view 截图法
* @param view
* @param name
* @throws Exception
*/
public static String SCREEN_SHOTS_LOCATION = Environment
.getExternalStorageDirectory().getPath();
public void takeScreenShot(View view, String name) throws Exception {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();
Canvas canvas = new Canvas(bitmap);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Paint paint = new Paint();
paint.setColor(Color.YELLOW);
SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String time = simple.format(new Date());
canvas.drawText(time, w - w / 2, h - h / 10, paint);
canvas.save();
canvas.restore();
FileOutputStream fos = null;
try {
File sddir = new File(SCREEN_SHOTS_LOCATION);
if (!sddir.exists()) {
sddir.mkdirs();
}
// image.setImageBitmap(bitmap);
File file = new File(SCREEN_SHOTS_LOCATION + File.separator
+ "screen" + ".png");
fos = new FileOutputStream(file);
if (fos != null) {
bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
}
} catch (Exception e) {
Log.e("tag", e.getCause().toString());
e.printStackTrace();
}
}
view的截图方法 也就是只能截取自己应用的界面