B4J Question SVG to PNG?

Bruce Axtens

Active Member
Licensed User
Longtime User
Does B4J have an SVG to PNG (or some other image format) conversion facility?
 

Bruce Axtens

Active Member
Licensed User
Longtime User
Sorry Erel, I'm a bit thick today. I've got this far:
B4X:
Sub wvMain_PageFinished (Url As String)
    Dim m As Map
    m.Initialize
    Dim count As Int = doScript(wvMain, "$('svg').length")
    Dim i As Int
    For i = 0 To count - 1
        Dim svg As String
        Dim scr As String = "var XMLS = new XMLSerializer(); var svg = ($('svg')[" & i & "]); XMLS.serializeToString(svg);"
        svg = doScript(wvMain, scr)
        m.Put(i,svg)
    Next
    Dim s As String = m.Get(0)
Do I .LoadHTML the 's' variable? Alternatively, how do I traverse the 16 svg nodes on the page?

Later
Sample SVG file added
 

Attachments

  • SVG_03.svg.xml
    140.7 KB · Views: 268
Last edited:
Upvote 0

Bruce Axtens

Active Member
Licensed User
Longtime User
Done. See above.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code works:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Dim wv As WebView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.Show
   wv.Initialize("wv")
   wv.LoadHtml(File.ReadString("C:\Users\H\Downloads\SVG_03.svg", ""))
   MainForm.RootPane.AddNode(wv, 0, 0, 200, 200)
End Sub

Sub MainForm_MouseClicked (EventData As MouseEvent)
   Dim out As OutputStream = File.OpenOutput(File.DirApp, "1.png", False)
   wv.Snapshot.WriteToStream(out)
   out.Close
End Sub
 
Upvote 0

Bruce Axtens

Active Member
Licensed User
Longtime User
Ah, wonderful. Thank you so much for that, Erel.
 
Upvote 0
Top