Android Question Webview CaptureBitmap error

hung

Active Member
Licensed User
Longtime User
I created a webview wv_img and loadurl to fill the conentent with some tables, and images.
Then do wv_img.CaptureBitmap to a bitmap. But this randomly failed.

B4X:
    Dim lbmp As Bitmap, lbok As Boolean

    lbok = False
    Dim cnt As Int
    For cnt = 0 To 50
        If lbok = False Then
            lbok = True
            wv_img.Invalidate
            Try
                lbmp = wv_img.CaptureBitmap
            Catch
                lbok = False
                Log("capturebitmap failed")
            End Try   
        End If
    Next

I suspected the wv_img.loadurl is slow then tried to wait until it is finished. But the event triggered far before it finish loading, i.e. immediate said "load url ok".

B4X:
Private wv_img As WebView

wv_img.LoadUrl(....)   
Wait For wv_img_PageFinished (url As String)
    Log("wv_img load url ok")

How could I wait for the page finish loading?
 

drgottjr

Expert
Licensed User
Longtime User
this:

Dim lbmp As Bitmap, lbok As Boolean

lbok = False
Dim cnt As Int
For cnt = 0 To 50
If lbok = False Then
lbok = True
wv_img.Invalidate
Try
lbmp = wv_img.CaptureBitmap
Catch
lbok = False
Log("capturebitmap failed")
End Try
End If
Next


needs to be destroyed immediately. i suggest fire.

although waiting for page load can usually solve a lot of problems, it depends on what is being loaded. for example, if a webpage runs a command to load another page or to perform some operation, page load only refers to the first webpage. the second load or the operation to be carried out are not covered. do you understand? it's like starting an automobile and then driving somewhere. starting the automobile = page load. driving somewhere = .....
you may need to wait for something else.
you might want to post the project.
 
Upvote 0

hung

Active Member
Licensed User
Longtime User
this:

Dim lbmp As Bitmap, lbok As Boolean

lbok = False
Dim cnt As Int
For cnt = 0 To 50
If lbok = False Then
lbok = True
wv_img.Invalidate
Try
lbmp = wv_img.CaptureBitmap
Catch
lbok = False
Log("capturebitmap failed")
End Try
End If
Next


needs to be destroyed immediately. i suggest fire.

although waiting for page load can usually solve a lot of problems, it depends on what is being loaded. for example, if a webpage runs a command to load another page or to perform some operation, page load only refers to the first webpage. the second load or the operation to be carried out are not covered. do you understand? it's like starting an automobile and then driving somewhere. starting the automobile = page load. driving somewhere = .....
you may need to wait for something else.
you might want to post the project.
The original program does one CaptureBitmap then found many time failure and stop my program.

The loop was to re-try CaptureBitmap with the hope with one time success. It helps many cases but there are still cases 50 retries failed.

The project has many parts. The above two codes describe the current problems. Thanks.
 
Upvote 0

hung

Active Member
Licensed User
Longtime User
this:

Dim lbmp As Bitmap, lbok As Boolean

lbok = False
Dim cnt As Int
For cnt = 0 To 50
If lbok = False Then
lbok = True
wv_img.Invalidate
Try
lbmp = wv_img.CaptureBitmap
Catch
lbok = False
Log("capturebitmap failed")
End Try
End If
Next


needs to be destroyed immediately. i suggest fire.

although waiting for page load can usually solve a lot of problems, it depends on what is being loaded. for example, if a webpage runs a command to load another page or to perform some operation, page load only refers to the first webpage. the second load or the operation to be carried out are not covered. do you understand? it's like starting an automobile and then driving somewhere. starting the automobile = page load. driving somewhere = .....
you may need to wait for something else.
you might want to post the project.
Understand about the page loading. It is exactly the cases so the Finished does not reflect the true, or in this case, it does not help.
 
Upvote 0
Top