Skip to main content
A newer version of this page is available. .

How to: Save a Picture to a File

Use the following API to save pictures to separate files.

API

Description

ReadOnlyShapeCollection.Get

Obtains shapes from the specified range

Shape.Picture

Retrieves the picture as an OfficeImage object.

OfficeImage.NativeImage

Provides access to the Image object.

Image.Save

Exports an image to the file.

The code sample below retrieves pictures from a specific range and save them as PNG images.

private void SaveImagesToFiles(Document document)
{
    DocumentRange myRange = document.CreateRange(0, 100);
    ReadOnlyShapeCollection images = document.Shapes.Get(myRange);
    if (images.Count > 0)
    {
        if (images[0].Picture != null)
        {
            DevExpress.Office.Utils.OfficeImage myImage = images[0].Picture;
            System.Drawing.Image image = myImage.NativeImage;
            string imageName = String.Format("Image_at_pos_{0}.png", images[0].Range.Start.ToInt());
            image.Save(imageName);
            System.Diagnostics.Process.Start("explorer.exe", "/select," + imageName);
        }
    }
}