• 4
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I want to take a screenshot of a web view after the page loading finished. So I try to add the getSnapShot() in onPageFinished(), but when call the getSnapShot(), the page is not loaded. So the picture of snapshot is blank.

And I load a local html file url, so I believe there is no redirect.

I also tried to make MyWebView extends WebView, override onDraw(), add a callback listener to call getSnapShot() at onDraw() process. But still not working.

webView.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);

        // will get a blank picture
        getSnapshot();
    }
});
    • getSnapshot() is a method of taking screenshot, familiar with your code. But the screenshot is blank when I call it in onPageFinished(), (I tried use a button to take screenshot manually when page displayed, it works out. But I want automatically take screenshot)....

Try this code;

 webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
    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( "your_directory_screenshot.jpg" );
          if ( fos != null )
         {
    b.compress(Bitmap.CompressFormat.JPEG, 100, fos);

      fos.close();
               }
         }
        catch( Exception e )
      {}
    }
});
  • 1
Reply Report