要獲得截圖中,你需要得到視圖
getWindow().getDecorView();
緩存視圖爲位圖的根佈局
public static File getScreenShot(Context context,View parentLayout)
{
parentLayout.setDrawingCacheEnabled(true);
Bitmap cachedBitmap= parentLayout.getDrawingCache();
Bitmap finalBitmap = cachedBitmap.copy(Bitmap.Config.RGB_565, true);
return saveBitmap(context,finalBitmap);
}
保存位圖中的設備或這種
private static File saveBitmap(Context context,Bitmap bitmap)
{
File snapShot=null;
try
{
String cacheDirectory=getCacheDirectory(context);
snapShot=new File(cacheDirectory, "Screenshot.png");
FileOutputStream out = new FileOutputStream(snapShot);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
} catch (Exception e)
{
e.printStackTrace();
}
return snapShot;
}
是這個程序刺探你的用戶嗎?我相信你應該首先檢查這項任務是否符合道德標準。 –