Loading wPicture

I want to replace a placeholder in a Word document by an image using:

Dim document As WordDocument = New WordDocument("Template.docx")
Dim myTextSelection as TextSelection = document.Find("MyPlaceHolder", False, False)
Dim paragraph As WParagraph = New WParagraph(document)
    Dim picture As WPicture = CType(paragraph.AppendPicture(Image.FromFile("C:\MyImage.png")), WPicture)
    Dim newSelection As TextSelection = New TextSelection(paragraph, 0, 1)
    Dim bodyPart As TextBodyPart = New TextBodyPart(document)
    bodyPart.BodyItems.Add(paragraph)
    document.Replace(textSelection.SelectedText, bodyPart, True, True)

But instead of loading wPicture from a file, I would like to load it from a memorystream or a PictureBox.Image.  I know it must be simple but I can't figure it out.  Can anyone provide guidance?  Thanks !




2 Replies 1 reply marked as answer

WI WindChaser November 20, 2024 07:03 PM UTC

Figured it out:


Dim picture As WPicture = CType(paragraph.AppendPicture(Image.FromStream(ms)), WPicture)


It's always the simplest things which fly under the radar.  


Thanks to anyone who read the post.




Marked as answer

CA Chrispine Agunja Imbo Syncfusion Team November 21, 2024 06:27 AM UTC

Hi WindChaser,

We are glad to know you figured it out. Feel free to contact us if you have any further questions.


Loader.
Up arrow icon