方法一:

 

 

01.
Picture snapShot = view.capturePicture();
02.

 

03.

 

04.
if (snapShot.getWidth() > 0 && snapShot.getHeight() > 0) {
05.
Bitmap b = Bitmap.createBitmap(snapShot.getWidth(),
06.
snapShot.getHeight(), Bitmap.Config.ARGB_8888);
07.

 

08.
Canvas c = new Canvas(b);
09.

 

10.
snapShot.draw(c);
11.

 

12.
Bitmap newBitmap = zoomBitmap(b, 250, 250);
13.
historyModel.setSnapshot(newBitmap);

 

方法二(經過測試,平板豎屏是經常截圖失敗, 原因是root.getDrawingCache()尺寸超過限制):

 

 

01.
View root = activity.getWindow().getDecorView();
02.

 

03.

 

04.
private Bitmap catchScreen(View root) {
05.
root.setDrawingCacheEnabled(true);
06.
root.setDrawingCacheBackgroundColor(0);
07.
root.buildDrawingCache(true);
08.
Bitmap b = root.getDrawingCache();
09.
return b;
10.
}

 

方法三(成功率高):

 

 

1.
// create snapshot for webview
2.
View cv = activity.getWindow().getDecorView();
3.
Bitmap b = Bitmap.createBitmap(cv.getWidth(), cv.getHeight(),
4.
Config.ARGB_4444);
5.
cv.draw(new Canvas(b));
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()