我有一个功能截图只有可见的屏幕,没有采取完整的WebView截图。
它不会提供隐藏或滚动的内容,只需捕捉当前视图。
这是我的代码。
public File getBitmapFromwebchartView(WebView view2) {
if (view2 != null) {
view2.setDrawingCacheEnabled(true);
Bitmap b = view2.getDrawingCache();
if (b != null) {
try {
//File fi = new File(Environment.getExternalStorageDirectory(), "Screenshot" + ".jpg");
fi = new File(Environment.getExternalStorageDirectory(),"Realitycheck" + ".jpg");
// write the bytes in file
FileOutputStream fo;
fo = new FileOutputStream(fi);
b.compress(CompressFormat.JPEG, 100, fo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return fi;
}
答案 0 :(得分:0)
TRY:
Picture picture = view.capturePicture();
Bitmap b = Bitmap.createBitmap( picture.getWidth(),
picture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas( b );
picture.draw( c );
FileOutputStream fos = null;
try {
fos = new FileOutputStream( "mnt/sdcard/screenshot.jpg" );
if ( fos != null )
{
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
}
}
catch(Exception e) {}