DocumentBuilderInsertImage Method (String, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType)
Inserts an image from a file or URL at the specified position and size.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.10
Syntax
public Shape InsertImage(
	string fileName,
	RelativeHorizontalPosition horzPos,
	double left,
	RelativeVerticalPosition vertPos,
	double top,
	double width,
	double height,
	WrapType wrapType
)

Parameters

fileName
Type: SystemString
The file that contains the image.
horzPos
Type: Aspose.Words.DrawingRelativeHorizontalPosition
Specifies where the distance to the image is measured from.
left
Type: SystemDouble
Distance in points from the origin to the left side of the image.
vertPos
Type: Aspose.Words.DrawingRelativeVerticalPosition
Specifies where the distance to the image measured from.
top
Type: SystemDouble
Distance in points from the origin to the top side of the image.
width
Type: SystemDouble
The width of the image in points. Can be a negative or zero value to request 100% scale.
height
Type: SystemDouble
The height of the image in points. Can be a negative or zero value to request 100% scale.
wrapType
Type: Aspose.Words.DrawingWrapType
Specifies how to wrap text around 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 a floating image from a file or URL.
[C#]

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertImage(ImageDir + "Watermark.png", RelativeHorizontalPosition.Margin, 100,
    RelativeVerticalPosition.Margin, 100, 200, 100, WrapType.Square);
Examples
Shows how to insert a floating image from a file or URL and retain the original image size in the document.
[C#]

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Pass a negative value to the width and height values to specify using the size of the source image.
builder.InsertImage(ImageDir + "LogoSmall.png", RelativeHorizontalPosition.Margin, 200,
    RelativeVerticalPosition.Margin, 100, -1, -1, WrapType.Square);
Examples
Shows different solutions of how to import an image into a document from a string.
[C#]

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("\nInserted image from string: ");
builder.InsertImage(ImageDir + "Aspose.Words.gif");

builder.Writeln("\nInserted image from string with a custom size: ");
builder.InsertImage(ImageDir + "Aspose.Words.gif", ConvertUtil.PixelToPoint(250),
    ConvertUtil.PixelToPoint(144));

builder.Writeln("\nInserted image from string using relative positions: ");
builder.InsertImage(ImageDir + "Aspose.Words.gif", RelativeHorizontalPosition.Margin, 100, 
    RelativeVerticalPosition.Margin, 100, 200, 100, WrapType.Square);

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