簡體   English   中英

將完整的Webview捕獲到位圖

[英]Capture Full Webview to Bitmap

我想問一下Webview:我無法在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());
                    }       
                }

這是給聽者的

            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);
                }

捕獲,滾動,捕獲,根據需要重復。

然后,如果需要,請組裝單個圖像。

提供此功能的外接瀏覽器工具似乎以相同的方式工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM