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.
Apache License 2.0
688 stars 69 forks source link

cannot capture a webview contents #13

Closed ghost closed 5 years ago

ghost commented 5 years ago

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

Muddz commented 5 years ago

Hi. Thanks for your post. Right now the next update will contain some refactoring and support for long list screenshot but I will take a look at Webviews too

On Tue, May 14, 2019, 23:02 Mr G Reaper (aka Dave) notifications@github.com wrote:

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Muddz/PixelShot/issues/13?email_source=notifications&email_token=ADRBS2EN5MBH5PO7HB5JRMLPVMSF3A5CNFSM4HM5URAKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GTYZKGA, or mute the thread https://github.com/notifications/unsubscribe-auth/ADRBS2DOYC546JG3TKUOAZ3PVMSF3ANCNFSM4HM5URAA .

ghost commented 5 years ago

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.

Muddz commented 5 years ago

Yes I will update you about any solutions

On Tue, May 14, 2019, 23:17 Mr G Reaper (aka Dave) notifications@github.com wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Muddz/PixelShot/issues/13?email_source=notifications&email_token=ADRBS2E5D4E7VM7LWDMSA6LPVMT5BA5CNFSM4HM5URAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVM2BWA#issuecomment-492413144, or mute the thread https://github.com/notifications/unsubscribe-auth/ADRBS2FYNMISZ4QOF5OV4ULPVMT5BANCNFSM4HM5URAA .

Muddz commented 5 years ago

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

ghost commented 5 years ago

As I say for me that creates a black screen shot (I am using kotlin and have to drop the result listener) If I use the same line for a normal view I get a screenshot so your library is working, just not for webview for me..... The webview is inside a fragment if that helps.

This has been during me nuts for a week now. All I need to do is make an image using a string.

On Fri, 17 May 2019, 19:08 Muddi Walid, notifications@github.com wrote:

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Muddz/PixelShot/issues/13?email_source=notifications&email_token=AARU7WG3NXAKI2IVJYJY553PV3YB7A5CNFSM4HM5URAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVVO5TQ#issuecomment-493547214, or mute the thread https://github.com/notifications/unsubscribe-auth/AARU7WFYVYCKIUHIK5LRCEDPV3YB7ANCNFSM4HM5URAA .

ghost commented 5 years ago

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

ghost commented 5 years ago

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)