B4J Question Paste image to HTMLeditor

JJ37

Member
I want to load an image from the harddrive and have it pasted into the HTMLeditor view. How can this be done from code?
 

JJ37

Member
Hi Erel. I made it work :) But I'd like you to look it over and perhaps correct it with the string literals.

B4X:
Private NewPath, NewFile As String
		Private fc As FileChooser
		fc.Initialize
		fc.Title="Browse and select a file"
		fc.SetExtensionFilter("Image", Array As String ("*.jpg", "*.png", "*.gif"))
		fc.InitialFileName = ""
		Private filename As String = fc.ShowOpen(MainForm)   'this is the FileChooser
	
			NewPath = File.GetFileParent(filename)
			NewFile = File.GetName(filename)
			
			Private b64 As Base64Image
			Private ImgStr As String
			
			' Read image as base64 string
			ImgStr = b64.EncodeFromImage(NewPath, NewFile)
			' Show it in HTMLeditor view
			HTMLEditor1.HtmlText = "<p><img src=""data:image/png;base64," & ImgStr & """/></p>"
It is based on a solution I found here
https://manual.mahara.org/en/18.04/tips/image_in_text.html
 
Top