当前位置:操作系统 > 安卓/Android >>

android webview 截图快照

方法一:    


Picture snapShot = view.capturePicture();


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

                Canvas c = new Canvas(b);

                snapShot.draw(c);

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

 


方法二(经过测试,平板竖屏是经常截图失败, 原因是root.getDrawingCache()尺寸超过限制):

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


    private Bitmap catchScreen(View root) {
        root.setDrawingCacheEnabled(true);
        root.setDrawingCacheBackgroundColor(0);
        root.buildDrawingCache(true);
        Bitmap b = root.getDrawingCache();
        return b;
    }

 

 

 

方法三(成功率高):

            // create snapshot for webview
            View cv = activity.getWindow().getDecorView();
            Bitmap b = Bitmap.createBitmap(cv.getWidth(), cv.getHeight(),
                    Config.ARGB_4444);
            cv.draw(new Canvas(b));

 

 


 

作者:fhy_2008
补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,