【发布时间】:2018-07-27 13:33:02
【问题描述】:
我想问一下 webview : 我无法在 webview 中捕获整页。我只能捕获仅出现在屏幕上的视图,因为我想捕获整个页面。怎么做?
这是我的网页视图:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
WebView.enableSlowWholeDocumentDraw();
}
setContentView(R.layout.main_activity);
final WebView webview = (WebView) findViewById(R.id.WebViewLayout);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(webview, url);
}
});
webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webview.setDrawingCacheEnabled(true);
webview.loadUrl("https://example.com");
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
Toast.makeText(this, "Bluetooth is not available",
Toast.LENGTH_LONG).show();
finish();
}
}
这是转换成位图
private void Print_BMP(){
Bitmap mBitmap = Bitmap.createBitmap(imageViewPicture.getDrawingCache());
int nMode = 0;
int nPaperWidth = 384;
if(width_58mm.isChecked())
nPaperWidth = 384;
if(mBitmap != null)
{
byte[] data = PrintPicture.POS_PrintBMP(mBitmap, nPaperWidth, nMode);
SendDataByte(Command.ESC_Init);
SendDataByte(Command.LF);
SendDataByte(data);
SendDataByte(PrinterCommand.POS_Set_PrtAndFeedPaper(30));
SendDataByte(PrinterCommand.POS_Set_Cut(1));
SendDataByte(PrinterCommand.POS_Set_PrtInit());
}
}
这是给keylistener的
private void KeyListenerInit() {
btnScanButton = (Button)findViewById(R.id.button_scan);
btnScanButton.setOnClickListener(this);
width_58mm = (RadioButton)findViewById(R.id.width_58mm);
width_58mm.setOnClickListener(this);
imageViewPicture = (WebView) findViewById(R.id.WebViewLayout);
imageViewPicture.setOnClickListener(this);
}
【问题讨论】:
标签: android cordova webview bitmap native