How to fill shape with picture in PowerPoint in C#

In order to change the look of a shape, users can add a solid, gradient, pattern or picture fill to it. Spire.Presentation supports all fill types listed. This article will introduce how to add a picture fill to a shape in C# and VB.NET.

Code Snippets:

Step 1: Initialize an instance of Presentation class.

Presentation ppt = new Presentation();

Step 2: Add a shape to the first slide.

IAutoShape shape = (IAutoShape)ppt.Slides[0].Shapes.AppendShape(ShapeType.DoubleWave, new RectangleF(100, 100, 400, 200));

Step 3: Set the FillType as picture and fill the shape with an image.

string picUrl = @"C:\Users\Administrator\Desktop\image.jpg";
shape.Fill.FillType = FillFormatType.Picture;               
shape.Fill.PictureFill.Picture.Url = picUrl;

Step 4: Set the picture fill mode to stretch.

shape.Fill.PictureFill.FillType = PictureFillType.Stretch;

Step 5: Save to file.

ppt.SaveToFile("shape.pptx", FileFormat.Pptx2010);

Output:

How to fill shape with picture in PowerPoint in C#

Full Code:

[C#]
Presentation ppt = new Presentation();

IAutoShape shape = (IAutoShape)ppt.Slides[0].Shapes.AppendShape(ShapeType.DoubleWave, new RectangleF(100, 100, 400, 200));
string picUrl = @"C:\Users\Administrator\Desktop\image.jpg";
shape.Fill.FillType = FillFormatType.Picture;                       
shape.Fill.PictureFill.Picture.Url = picUrl;
shape.Fill.PictureFill.FillType = PictureFillType.Stretch;
shape.ShapeStyle.LineColor.Color = Color.Transparent;

ppt.SaveToFile("shape.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("shape.pptx");
[VB.NET]
Dim ppt As Presentation = New Presentation()

Dim shape As IAutoShape = CType(ppt.Slides(0).Shapes.AppendShape(ShapeType.DoubleWave, New RectangleF(100, 100, 400, 200)), IAutoShape)
Dim picUrl As String = "C:\Users\Administrator\Desktop\image.jpg"
shape.Fill.FillType = FillFormatType.Picture
shape.Fill.PictureFill.Picture.Url = picUrl
shape.Fill.PictureFill.FillType = PictureFillType.Stretch
shape.ShapeStyle.LineColor.Color = Color.Transparent

ppt.SaveToFile("shape.pptx", FileFormat.Pptx2010)
System.Diagnostics.Process.Start("shape.pptx")