Webview CaptureBitMap- Java Exception Width and height must be > 0

citywest

Member
Licensed User
Longtime User
If you look at the following code it works if the MsgBox is un-commented in the PageFinished Sub. If left as commented then Java Exception "width and height must be > 0" occurs.

I have tried everything I can think of to resolve this without any joy. Any help is greatly appreciated.

Attached is a Project File which shows this.

Thanks in advance,

Mark S.
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 PageView As WebView
   PageView.Initialize("PageView")
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")

    Activity.AddView(PageView, 0, 0, 100%x, 100%y)
   File.Copy(File.DirAssets, "manual_p1.htm", File.DirInternal, "manual_p1.htm")
   PageView.LoadUrl("File:///" & File.DirInternal & "/manual_p1.htm")
   PageView.Visible = True
      
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub PageView_PageFinished(Url As String)
    'Msgbox("Page Finished Loading", "")
   Dim PageBmp As Bitmap
   PageBmp.Initialize3(PageView.CaptureBitmap)
End Sub
 

Attachments

  • CaptureBitMapTest.zip
    6.6 KB · Views: 207
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
A bit ugly but should work:
B4X:
'Activity module
Sub Process_Globals
   Private captureTimer As Timer
   Private retries As Int
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 PageView As WebView
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   PageView.Initialize("PageView")

    Activity.AddView(PageView, 0, 0, 100%x, 100%y)
   File.Copy(File.DirAssets, "manual_p1.htm", File.DirInternal, "manual_p1.htm")
   PageView.LoadUrl("file:///" & File.DirInternal & "/manual_p1.htm")
   PageView.Visible = True
   captureTimer.Initialize("CaptureTimer", 200)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub PageView_PageFinished(Url As String)
   retries = 0
   captureTimer.Enabled = True
End Sub
Sub CaptureTimer_Tick
   Try
      Dim PageBmp As Bitmap
      PageBmp.Initialize3(PageView.CaptureBitmap)
      'do whatever you need with the bitmap
      captureTimer.Enabled = False   
   Catch
      Log("Failed to capture: " & retries)
      retries = retries + 1
      If retries = 3 Then captureTimer.Enabled = False
   End Try
End Sub
 
Upvote 0

supriono

Member
Licensed User
Longtime User
A bit ugly but should work:
B4X:
'Activity module
Sub Process_Globals
   Private captureTimer As Timer
   Private retries As Int
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 PageView As WebView
  
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   PageView.Initialize("PageView")

    Activity.AddView(PageView, 0, 0, 100%x, 100%y)
   File.Copy(File.DirAssets, "manual_p1.htm", File.DirInternal, "manual_p1.htm")
   PageView.LoadUrl("file:///" & File.DirInternal & "/manual_p1.htm")
   PageView.Visible = True
   captureTimer.Initialize("CaptureTimer", 200)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub PageView_PageFinished(Url As String)
   retries = 0
   captureTimer.Enabled = True
End Sub
Sub CaptureTimer_Tick
   Try
      Dim PageBmp As Bitmap
      PageBmp.Initialize3(PageView.CaptureBitmap)
      'do whatever you need with the bitmap
      captureTimer.Enabled = False  
   Catch
      Log("Failed to capture: " & retries)
      retries = retries + 1
      If retries = 3 Then captureTimer.Enabled = False
   End Try
End Sub
hello erel:
i have found this error in my android
401 unauthorized
your client does not have permision to get URL /cgi-bin/view/image from this server.

i want to get same image from IP camera with this URL
http://192.168.0.100:8080/cgi-bin/view/image (in mozila URL fine)

B4X:
Sub Activity_Create(FirstTime As Boolean)

   'Do not forget to load the layout file created with the visual designer. For example:

   'Activity.LoadLayout("Layout1")

   PageView.Initialize("PageView")

    Activity.AddView(PageView, 0, 0, 100%x, 100%y)

   PageView.LoadUrl("http://192.168.0.100:8080/cgi-bin/view/image")

   PageView.Visible = True

   captureTimer.Initialize("CaptureTimer", 200)

End Sub


my IP camera is TPlink SC3030...

user : admin
pas:admin

i think before get image, must log in to IP camera with user and pas
can u help me...
 
Upvote 0

Licht2002

Member
Licensed User
Longtime User
Hi Erel,

i tried this example with an webcam.... but it do not work.

Do i something wrong?

Thanks
Tom



Add to Manifest android:hardwareAccelerated="true"
B4X:
Sub Process_Globals
  Private captureTimer As Timer
  Private retries As Int
  Dim bmp As Bitmap
  Dim y As Int
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 PageView As WebView
 
End Sub

Sub Activity_Create(FirstTime As Boolean)
  'Do not forget to load the layout file created with the visual designer. For example:
  'Activity.LoadLayout("Layout1")
  PageView.Initialize("PageView")

  Activity.AddView(PageView, 0, 0, 100%x, 100%y)
  PageView.LoadUrl("http://www.earthcam.com/usa/nevada/lasvegas/index.php?cam=sign_hd")
  PageView.Visible = True
  captureTimer.Initialize("CaptureTimer", 500)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub PageView_PageFinished(Url As String)
  retries = 0
  captureTimer.Enabled = True
End Sub
Sub CaptureTimer_Tick
  Try
      bmp = PageView.CaptureBitmap
      y = bmp.Height
      Log ("Y bmp: " & y)
      'do whatever you need with the bitmap
      captureTimer.Enabled = False 
  Catch
      Log("Failed to capture: " & retries)
      retries = retries + 1
      If retries = 3 Then captureTimer.Enabled = False
  End Try
End Sub
 
Upvote 0
Top