在pc上的軟體很多,但是android上的比較少,所以就自己寫了一個,下面時軟體的核心代碼private Bitmap getViewBitmap(View v) { // 將一個View轉化成一張圖片
v.clearFocus(); // 清除視圖焦點
v.setPressed(false);// 將視圖設為不可點擊
boolean willNotCache = v.willNotCacheDrawing(); // 返回視圖是否可以儲存他的畫圖緩衝
v.setWillNotCacheDrawing(false);
// Reset the drawing cache background color to fully transparent
// for the duration of this operation //將視圖在此操作時置為透明
int color = v.getDrawingCacheBackgroundColor(); // 獲得繪製緩衝位元影像的背景顏色
v.setDrawingCacheBackgroundColor(0); // 設定繪圖背景顏色
if (color != 0) { // 如果獲得的背景不是黑色的則釋放以前的繪圖緩衝
v.destroyDrawingCache(); // 釋放繪圖資源所使用的緩衝
}
v.buildDrawingCache(); // 重新建立繪圖緩衝,此時的背景色是黑色
Bitmap cacheBitmap = v.getDrawingCache(); // 將繪圖緩衝得到的,注意這裡得到的只是一個映像的引用
if (cacheBitmap == null) {
return null;
}
Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // 將位元影像執行個體化
// Restore the view //恢複視圖
v.destroyDrawingCache();// 釋放位元影像記憶體
v.setWillNotCacheDrawing(willNotCache);// 返回以前緩衝設定
v.setDrawingCacheBackgroundColor(color);// 返回以前的緩衝顏色設定
return bitmap;
}
http://xiangqianppp-163-com.iteye.com/blog/1457688