Android視圖的截圖

來源:互聯網
上載者:User

在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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.