DocumentBuilderInsertImage Method (Stream)
Inserts an image from a stream into the document. The image is inserted inline and at 100% scale.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.12
Syntax
public Shape InsertImage(
	Stream stream
)

Parameters

stream
Type: System.IOStream
The stream that contains the image.

Return Value

Type: Shape
The image node that was just inserted.
Remarks

You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

Examples
Shows how to insert an image from a stream. The image is inserted inline and at 100% scale.
// This creates a builder and also an empty document inside the builder.
DocumentBuilder builder = new DocumentBuilder();

Stream stream = File.OpenRead(MyDir + "Images/Aspose.Words.gif");
try
{
    builder.Write("Image from stream: ");
    builder.InsertImage(stream);
}
finally
{
    stream.Close();
}

builder.Document.Save(ArtifactsDir + "Image.CreateFromStream.doc");
Examples
Shows different solutions of how to import an image into a document from a stream.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

using (Stream stream = File.OpenRead(ImageDir + "Aspose.Words.gif"))
{
    builder.Writeln("Inserted image from stream: ");
    builder.InsertImage(stream);

    builder.Writeln("\nInserted image from stream with a custom size: ");
    builder.InsertImage(stream, ConvertUtil.PixelToPoint(250), ConvertUtil.PixelToPoint(144));

    builder.Writeln("\nInserted image from stream using relative positions: ");
    builder.InsertImage(stream, RelativeHorizontalPosition.Margin, 100, RelativeVerticalPosition.Margin,
        100, 200, 100, WrapType.Square);
}

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