【问题标题】:Capture Full Webview to Bitmap将完整的 Web 视图捕获到位图
【发布时间】: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


    【解决方案1】:

    必要时捕捉、滚动、捕捉、重复。

    然后根据需要组装各个图像。

    提供此功能的插件浏览器工具似乎以同样的方式工作。

    【讨论】:

    • 请任何人帮助我的问题:(
    猜你喜欢
    • 2011-12-29
    • 2013-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多