ReplaceImage.vb
''
'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Word

'' This sample loads an existing document, And replaces
'' the (only) image in it with a different one.
Public Class ReplaceImage
    Public Function CreateDocx() As GcWordDocument
        '' The New image data
        Dim picBytes = File.ReadAllBytes(Path.Combine("Resources", "ImagesBis", "DianeForsyth.jpg"))

        '' Load the document
        Dim doc = New GcWordDocument()
        doc.Load(Path.Combine("Resources", "WordDocs", "ProcurementLetter.docx"))

        '' Access the image to replace
        Dim pic = doc.Body.Sections.First.GetRange().Pictures.First
        '' Replace the image data in place:
        pic.ImageData.SetImage(picBytes, "image/jpeg")

        '' Done
        Return doc
    End Function
End Class