Android Question WebView: CaptureBitmap

deyvitm

Member
Licensed User
Longtime User
English:

I'm using webview and then captured the image with CaptureBitmap (keep it in File.DirRootExternal), then from another button "Export" copy the generated image (File.DirRootExternal) to the gallery image, then another button mailed the image generated (File.DirRootExternal), my problem is that when I generate the image with CaptureBitman (File.DirRootExternal) image sometimes goes well and sometimes cut off (see the picture only when there has been a part of the image :()

Spanish:

Estoy usando webview y luego capturo la imagen con CaptureBitmap( la guardo en File.DirRootExternal), luego desde otro boton "Exportar" copio la imagen generada(File.DirRootExternal) a la galeria de imagen, luego con otro boton envio por correo la imagen generada(File.DirRootExternal), mi problema es que cuando genero la imagen con CaptureBitman(File.DirRootExternal) algunas veces la imagen sale bien y otras veces sale cortada( cuando veo la imagen solo se ha generado una parte de la imagen :( )



Copy the code:

B4X:
Sub Globals
Dim wve As WebViewExtras
     Dim wv As WebView   
    
End Sub

'I call the webview
Sub lvwBusqueda_ItemClick (Position As Int, Value As Object)
       
        Dim UrlBrowser As String = "http://...."

        wve.addJavascriptInterface(wv, "B4A")
        wve.addWebChromeClient(wv, "")   
        wv.LoadUrl(UrlBrowser)       
        wv.SetLayout(1%x,1%y,98%x,78%y)           
        wv.Visible = True
        wv.BringToFront
End Sub


'the image is created
Sub wv_PageFinished (Url As String)   
Dim Javascript As String
    Javascript="B4A.CallSub('Process_HTML', false, document.documentElement.outerHTML)"       
    wve.executeJavascript(wv, Javascript)
       
    NombreImagenContador = "Imagen1.png"   
Dim Out As OutputStream
    Out = File.OpenOutput(File.DirRootExternal, NombreImagenContador, False)
    wv.CaptureBitmap.WriteToStream(Out, 100, "PNG")
    Out.Close

End Sub
        
Sub Process_HTML(Html As String)   
   
End Sub

'Copy the generated image to the gallery
Sub btnExportarImagen_Click
    Dim i As Intent
    i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", "file://" & File.Combine(File.DirRootExternal, "Imagen1.png" ))
    Dim p As Phone
    p.SendBroadcastIntent(i)

End Sub


'Send Email Image
Sub btnSend_Click
SubirArchivoConSOAP("UserName","Password", _
                txtEmails.Text.Trim, "11111")
End Sub


Sub SubirArchivoConSOAP(Usuario As String, Clave As String, Para As String, codigo As String)    
    Private Base64Con As Base64Image   
    Private B64Str As String = Base64Con.EncodeFromImage(File.DirRootExternal, "Imagen1.png")
    Private jobSendEmail As HttpJob   
    Dim XML As String
   
    XML = ""
    XML = XML & "<?xml version='1.0' encoding='utf-8'?>"
    XML = XML & "<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>"
    XML = XML & "<soap12:Body>"
    XML = XML & "<EnviarCorreo xmlns='http://tempuri.org/'>"
    XML = XML & "<usuario>" & Usuario & "</usuario>"
    XML = XML & "<clave>" & Clave & "</clave>"
    XML = XML & "<para>" & Para & "</para>"   
    XML = XML & "<codigo>" & codigo & "</codigo>"   
    XML = XML & "<bimagen>" & B64Str & "</bimagen>"   
    XML = XML & "</EnviarCorreo>"
    XML = XML & "</soap12:Body>"
    XML = XML & "</soap12:Envelope>"
    XML = XML.Replace("'", Chr(34))
    jobSendEmail.Initialize("jobSendEmail", Me)   
    jobSendEmail.PostString ("http://../../service.asmx", XML)
    jobSendEmail.GetRequest.SetContentType("application/soap+xml; charset=utf-8")
End Sub


Not know what else I can do, I'm going crazy, please I need your urgent help, thank you very much!


THX

Deyvi
 
Top