D
D
dizar472015-05-04 18:35:42
Android
dizar47, 2015-05-04 18:35:42

How to take a snapshot of WebView content?

Nexus 5. Android Lollipop 5.1. Xamarin.
I use this code to save conversations from m.vk.com as images. These are not exactly screenshots, but a snapshot of the contents of the WebView. Sometimes they come out 20000px high, i.e. significantly larger than the visible area of ​​the WebView. It used to work fine, but recently the snapshot is the same size, but it only has the visible area of ​​the WebView and a bunch of gray background. I suspect that the reason is the WebView refresh. How can this be fixed?

public override void OnPageFinished (WebView view, string url)
    {			
      Picture picture = view.CapturePicture ();
      Bitmap bmp = Bitmap.CreateBitmap (picture.Width, picture.Height, Bitmap.Config.Argb8888);
      Canvas canvas = new Canvas (bmp);
      picture.Draw (canvas);
      MainActivity.Save(bmp);
}

UPD. Removed all WebView updates and everything works as before. But the decision is extremely doubtful.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Pukhov, 2015-05-05
@Neuroware

usually such functionality is not cut out for a clean one (unless they thought it was a bug), so most likely they moved it into some kind of separate function.

D
dizar47, 2015-06-20
@dizar47

UPD:
Before creating a WebView, you need to call this static procedure
WebView.EnableSlowWholeDocumentDraw();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question