The function of an instance is to add a picture to the HTML img tag.
You can encode the image in base64. For example
<src= "Data:image/gif;base64,myimagedataencodedinbase64
= " alt=" My Image data in base "/>
Here are a full example of what can accomplish this:
usingSystem;usingSystem.IO;usingSystem.Runtime.InteropServices;usingSystem.Windows.Forms;namespaceimageencodedinbase64inawebbrowser{[ComVisible (true)] Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidForm1_Load (Objectsender, EventArgs e) { stringurl = directory.getcurrentdirectory () +"\\page.html"; Webbrowser1.url=NewUri (URL); Webbrowser1.objectforscripting= This; } Private voidButton1_Click (Objectsender, EventArgs e) { stringImageInBase64 =ReadImageInBase64 (); WebBrowser1.Document.InvokeScript ("Setimagedata",New[] {imageInBase64}); } Private stringReadImageInBase64 () {stringImagePath = directory.getcurrentdirectory () +"\\opensource.png"; using(varFS =NewFileStream (ImagePath, FileMode.Open, FileAccess.Read)) { varBuffer =New byte[FS. Length]; Fs. Read (Buffer,0, (int) fs. Length); returnconvert.tobase64string (buffer); } } }}
And this Javascript code:
function Setimagedata (imageBase64) { var myimg = document.getElementById ("myimg"); = "Data:image/png;base64," + imageBase64;}
Triggers JavaScript in the HTML page in the WebBrowser.