Android Question webview.CaptureBitmap.WriteToStream - help needed

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hi

i'm trying to save a webview content as image using this

B4X:
Dim out As OutputStream
    out.InitializeToBytesArray(1000)
    out =  File.OpenOutput(File.DirInternal, "image.jpg",False)
    Text_WebView.CaptureBitmap.WriteToStream(out,100,"JPG")
    out.Close

with or without Erel's following code called as he said from activity_create
B4X:
Sub EnableSlowWebViewDocumentDraw
    Dim p As Phone
    If p.SdkVersion >= 21 Then
        Dim jo As JavaObject
        jo.InitializeStatic("android.webkit.WebView").RunMethod("enableSlowWholeDocumentDraw", Null)
    End If
End Sub

i get the following error (on the bold line in my code)
java.lang.IllegalArgumentException: No enum constant android.graphics.Bitmap.CompressFormat.JPG
at java.lang.Enum.valueOf(Enum.java:300)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8919)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

help...

thanks
 
Solution
problem solved using this correction

B4X:
Dim out As OutputStream
    out = File.OpenOutput(File.Dirinternal, "image.png", False)
    Text_WebView.CaptureBitmap.WriteToStream(out, 100, "PNG")
    out.Close

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
problem solved using this correction

B4X:
Dim out As OutputStream
    out = File.OpenOutput(File.Dirinternal, "image.png", False)
    Text_WebView.CaptureBitmap.WriteToStream(out, 100, "PNG")
    out.Close
 
Upvote 0
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…