展会信息港展会大全

android webview 截图快照
来源:互联网   发布日期:2015-10-02 21:34:59   浏览:1312次  

导读:方法一: 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.d...

方法一:

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开发 教程

相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港