Apply Transparency to Image in PowerPoint in C#, VB.NET

When you position some text over an image shape, you may want to make the image lighter or transparent so it doesn’t interfere with text. This article will demonstrate how to apply transparency to the image inside of a shape using Spire.Presentation with C# and VB.NET.

Step 1: Create a Presentation instance.

Presentation presentation = new Presentation();

Step 2: Create an Image from the specified file.

string imagePath = "logo.png";
Image image = Image.FromFile(imagePath);

Step 3: Add a shape to the first slide.

float width = image.Width;
float height = image.Height;
RectangleF rect = new RectangleF(50, 50, width, height);
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rect);
shape.Line.FillType = FillFormatType.None;

Step 4: Fill the shape with image.

shape.Fill.FillType = FillFormatType.Picture;
shape.Fill.PictureFill.Picture.Url = imagePath;
shape.Fill.PictureFill.FillType = PictureFillType.Stretch;

Step 5: Set transparency on the image.

shape.Fill.PictureFill.Picture.Transparency = 50;

Step 6: Save to file.

presentation.SaveToFile("output.pptx", FileFormat.Pptx2013);

Output:

Apply Transparency to Image in PowerPoint in C#, VB.NET

Full Code:

[C#]
//create a PowerPoint document
Presentation presentation = new Presentation();
string imagePath = "logo.png";
Image image = Image.FromFile(imagePath);
float width = image.Width;
float height = image.Height;
RectangleF rect = new RectangleF(50, 50, width, height);
//add a shape
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rect);
shape.Line.FillType = FillFormatType.None;
//fill shape with image
shape.Fill.FillType = FillFormatType.Picture;
shape.Fill.PictureFill.Picture.Url = imagePath;
shape.Fill.PictureFill.FillType = PictureFillType.Stretch;
//set transparency on image
shape.Fill.PictureFill.Picture.Transparency = 50;
//save file
presentation.SaveToFile("output.pptx", FileFormat.Pptx2013);
[VB.NET]
'create a PowerPoint document
Dim presentation As Presentation = New Presentation()
Dim imagePath As String = "logo.png"
Dim image As Image = Image.FromFile(imagePath)
Dim width As single = image.Width
Dim height As single = image.Height
Dim rect As RectangleF = New RectangleF(50,50, width, height)
'add a shape
Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, rect)
shape.Line.FillType = FillFormatType.None
'fill shape with image
shape.Fill.FillType = FillFormatType.Picture
shape.Fill.PictureFill.Picture.Url = imagePath
shape.Fill.PictureFill.FillType = PictureFillType.Stretch
'set transparency on image
shape.Fill.PictureFill.Picture.Transparency = 50
'save file
presentation.SaveToFile("output.pptx", FileFormat.Pptx2013)