灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:3833回复:0

android webview 截图快照

楼主#
更多 发布于:2012-09-06 14:05


方法一:    

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

喜欢0 评分0
游客

返回顶部