// This code is part of Document Solutions for Word demos.
// Copyright (c) MESCIUS inc. All rights reserved.
using System;
using System.IO;
using System.Drawing;
using GrapeCity.Documents.Word;

namespace DsWordWeb.Demos
    // This sample loads an existing document, and replaces
    // the (only) image in it with a different one.
    public class ReplaceImage
        public GcWordDocument CreateDocx()
            // The new image data:
            var picBytes = File.ReadAllBytes(Path.Combine("Resources", "ImagesBis", "DianeForsyth.jpg"));

            // Load the document:
            var doc = new GcWordDocument();
            doc.Load(Path.Combine("Resources", "WordDocs", "ProcurementLetter.docx"));

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

            // Done:
            return doc;