Muddz / QuickShot

[Moved to MavenCentral] Capture images of any View, SurfaceView or Bitmap from your Android app in: .jpg .png or .nomedia with simple oneliner codes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot capture a webview contents

opened this issue · comments

I am using Kotlin and trying to capture a webviews contents (including data outside of the screen area) the old java methods I use to use are depraciated (bless google for making things tough)
at first your library seemed like a godsend but I can not get it to work for my needs.

PixelShot.of(generator_webview).save()
captures a blank image

PixelShot.of(generator_webview.view().rootView).save()
captures an image as though the user has used thier phones screenshot function (ie full ui is shown, anything off screen is not etc) impressive how easy that is to do with your library but alas not my goal.

I also could not use the callback code as I can not implement a java class in a kotlin class...thats a lesser issue though

Appreciated, had not expected a response so fast.
for reference:
PixelShot.of(generator_webview.rootView).save()
achieves the same result as
PixelShot.of(generator_webview.view().rootView).save()
forgot I was using anko..... still only takes a screenshot of the actual screen

In my case the webview is inside a fragment, the root view is ofcourse the fragments container.

The issue has been driving me nuts all night as I try different ways but will wait to see the update (plenty of other parts of my app I need to work on so no real rush, but can you update this thread after you have looked at it, even if its something not possible.

Thanks in advance.

Hi. I manged to get it work. No updates needed.

This is my line of code PixelShot.of(webview).setResultListener(this).save();

Please try it

I am a step closer to a solution. Found out the reason I get a blank screen is that I turn the background of the webview transparent (this is so the "paper" image can be seen behind the text when displayed in the app) if I turn it to white the the image saves the webview with the code you provided (minus result listener as I cant implement that in kotlin)
Sorry about that had not occured to me it would be making the images black text on black background for transparent views.

However there is another issue, 90% of the data I display (my app randomly generates text for a table top game) goes off screen, it's why I use a webview to display the String. But the image captured only shows the content that was displayed, cutting off any unscrolled text.
So close to a solution

I ended up creating my own code for saving the bitmap and had the same issue, it was not saving all the view, only what was seen.

This was down to the view not passing on the height correctly
This was my StackOverflow question which will show more detail https://stackoverflow.com/questions/56209840/how-do-i-turn-all-of-a-webview-content-into-a-bitmap/56210175#56210175

I fixed it in the end by forcing it to measure the view and then getting the measured view (not sure if that would be possible with the pixelshot library but provide the solution incase others hit the same issue)

I also fixed the issue of the image saving as black if the webview background is transparent
canvas.drawColor(-0x1) solved that (basically just making the default colour white)