Android Question how to get Canvas bitmap from JavaScript ?

Discussion in 'Android Questions' started by peacemaker, May 16, 2019.

  1. peacemaker

    peacemaker Well-Known Member Licensed User

    HI, All

    If web-page makes the image by drawing on Canvas - how to get it ?
    Source:
    Code:
    <canvas id="canvas" width="1024" height="500" class="chartjs-render-monitor" style="display: block;"></canvas>
    Code:
    Dim Javascript As String = "B4A.CallSub('Page_finished', true, document.getElementById('canvas'))"
        WebViewExtras1.executeJavascript(Javascript)
    End Sub

    Sub Page_finished(HTML As String)
        
    Log(HTML)
    ....
    Here the result is "undefined". How correctly to do ?
     
  2. peacemaker

    peacemaker Well-Known Member Licensed User

    SOLVED:

    Code:
    Sub Process_Start
      
    Dim Javascript As String = "B4A.CallSub('Page_finished', true, document.getElementById('canvas').toDataURL())"
        WebViewExtras1.executeJavascript(Javascript)
    End Sub


    Sub wvc_PageFinished(URL As String)
        Sleep(
    1000)    'required: time for drawing on canvas
        Process_Start
    End Sub


    Sub Page_finished(HTML As String)
        
    Dim a As String = HTML.Replace("data:image/png;base64,""")
        
    Dim su As StringUtils
     
        
    Dim FileBytes() As Byte = su.DecodeBase64(a)
        
    Dim InStream As InputStream
        InStream.InitializeFromBytesArray(FileBytes, 
    0, FileBytes.Length)
        
    Dim b As Bitmap
        b.Initialize2(InStream)
        InStream.Close
        ImageView1.Bitmap = b
     
    José J. Aguilar likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice