ImageDataSetImage Method (Stream)

Sets the image that the shape displays.

Namespace:  Aspose.Words.Drawing
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public void SetImage(
	Stream stream
)

Parameters

stream
Type: System.IOStream
The stream that contains the image.
Examples
Shows two ways of importing images from the local file system into a document.
Document doc = new Document();

// We can get an image from a file, set it as the image of a shape and append it to a paragraph
Image srcImage = Image.FromFile(ImageDir + "Logo.jpg");

Shape imgShape = new Shape(doc, ShapeType.Image);
doc.FirstSection.Body.FirstParagraph.AppendChild(imgShape);
imgShape.ImageData.SetImage(srcImage);
srcImage.Dispose();

// We can also open an image file using a stream and set its contents as a shape's image 
using (Stream stream = new FileStream(ImageDir + "Logo.jpg", FileMode.Open, FileAccess.Read))
{
    imgShape = new Shape(doc, ShapeType.Image);
    doc.FirstSection.Body.FirstParagraph.AppendChild(imgShape);
    imgShape.ImageData.SetImage(stream);
    imgShape.Left = 150.0f;
}

doc.Save(ArtifactsDir + "Drawing.ImportImage.docx");
See Also