WebView CaptureBitmap

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hello,

I would like to capture the bitmap of an entire webpage with WebBrowser1.CaptureBitmap, however I receive the following error:
java.lang.IllegalArgumentException: width and height must be > 0

when WebBrowser1.CaptureBitmap is called.

Here is my code:

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim WebView1 As WebView
        Dim btmp As bitmap
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Downloader.bal")
   WebView1.JavaScriptEnabled = True
   WebView1.ZoomEnabled = True
   'btmp.InitializeMutable(500,800)
End Sub

Sub Activity_Resume
   WebView1.LoadUrl("http://www.rootsoftllc.com")
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebView1_PageFinished (Url As String)
   'btmp = WebView1.CaptureBitmap 
        Dim out As OutputStream
        out.InitializeToBytesArray(1000)
        Dim data() As Byte
        WebView1.CaptureBitmap.WriteToStream(out,100,"PNG") 
   data = out.ToBytesArray
End Sub

Can anyone help me please?

Tomas
 

carloz

Member
Licensed User
Longtime User
how?

hi tomas,

im having a similar problem. i have a webview and a button on a panel,
on button click webview.capturebitmap gives the same error as yours.
the webview visible property is true in the designer.
what else do i neex to do? how did you solve it,plz help

regards
carloz
 
Upvote 0

aletrotta

New Member
Licensed User
Longtime User
Hi Carloz,

Have you try to set WebView1.Visible = True by code?
I was having the error above, and by adding that line to the code it worked.


'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Dim WebView1 As WebView
Dim ImageView1 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
WebView1.LoadUrl("http://www.dolarsi.com/cotizador/cotizador_verde_full.asp")
WebView1.Visible = True ' Without this line got error java.lang.IllegalArgumentException: width and height must be > 0
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebView1_PageFinished (Url As String)
Dim Bmp As Bitmap
Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal, "dolarsi.png", False)
WebView1.CaptureBitmap.WriteToStream(Out, 100, "PNG")
Out.Close

ImageView1.Bitmap = LoadBitmap(File.DirRootExternal, "dolarsi.png")
End Sub
 
Upvote 0

Agnetha

Member
Licensed User
Longtime User
Hi!

I have the same error, too.
Although i set visible = true.
Have you got already a solution?

regards, Agnetha.
 
Upvote 0
Top