Apply 3D Effects in PowerPoint using C#

3D effects in PowerPoint presentations make the content more attractive. Using 3D text or shapes, you can enhance the interactivity and catch the attention of the audience. While working on the automation of PowerPoint from within .NET applications, you may need to add 3D effects to the presentations. To accomplish that, this article covers how to apply the 3D effects in PowerPoint PPT in C#.

.NET API to Apply 3D Effects in PowerPoint

Aspose.Slides for .NET is an amazing API that provides a range of features to implement PowerPoint automation. Using the API, you can create and manipulate presentations seamlessly. We will use this API to apply 3D effects in the PowerPoint presentations. You can either download API’s DLL or install it using NuGet.

PM> Install-Package Aspose.Slides.NET 

Create a 3D Text in PowerPoint in C#

The following are the steps to create a 3D text fragment in PowerPoint PPT using C#.

The following code sample shows how to create a 3D text in PowerPoint in C#.

// Create presentation
using (Presentation presentation = new Presentation())
{
// Create a rectangle shape
IAutoShape shape = presentation.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 200, 150, 250, 250);
shape.FillFormat.FillType = FillType.NoFill;
shape.LineFormat.FillFormat.FillType = FillType.NoFill;
shape.TextFrame.Text = "3D Text";
// Get text portion
Portion portion = (Portion)shape.TextFrame.Paragraphs[0].Portions[0];
portion.PortionFormat.FillFormat.FillType = FillType.Pattern;
portion.PortionFormat.FillFormat.PatternFormat.ForeColor.Color = Color.DarkOrange;
portion.PortionFormat.FillFormat.PatternFormat.BackColor.Color = Color.White;
portion.PortionFormat.FillFormat.PatternFormat.PatternStyle = PatternStyle.LargeGrid;
shape.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 128;
// Access text frame
ITextFrame textFrame = shape.TextFrame;
// Set up "Arch Up" WordArt transform effect
textFrame.TextFrameFormat.Transform = TextShapeType.ArchUp;
// Apply 3D effects
textFrame.TextFrameFormat.ThreeDFormat.ExtrusionHeight = 3.5f;
textFrame.TextFrameFormat.ThreeDFormat.Depth = 3;
textFrame.TextFrameFormat.ThreeDFormat.Material = MaterialPresetType.Plastic;
textFrame.TextFrameFormat.ThreeDFormat.LightRig.Direction = LightingDirection.Top;
textFrame.TextFrameFormat.ThreeDFormat.LightRig.LightType = LightRigPresetType.Balanced;
textFrame.TextFrameFormat.ThreeDFormat.LightRig.SetRotation(0, 0, 40);
textFrame.TextFrameFormat.ThreeDFormat.Camera.CameraType = CameraPresetType.PerspectiveContrastingRightFacing;
// Save presentation
presentation.Save("3D-Text.pptx", SaveFormat.Pptx);
}

The following screenshot shows output of the code sample above.

Create a 3D Text in PowerPoint in C#

Create a 3D Shape in PowerPoint in C#

Similar to text, you can apply 3D effects to the shapes in PowerPoint presentations. The following are the steps to create a 3D shape in PowerPoint in C#.

The following code sample shows how to apply 3D effects to shapes in PowerPoint using C#.

// Create presentation
using (Presentation presentation = new Presentation())
{
// Add a new shape
IAutoShape shape = presentation.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);
// Set text
shape.TextFrame.Text = "3D";
shape.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 64;
// Apply 3D effects
shape.ThreeDFormat.Camera.CameraType = CameraPresetType.OrthographicFront;
shape.ThreeDFormat.Camera.SetRotation(20, 30, 40);
shape.ThreeDFormat.LightRig.LightType = LightRigPresetType.Flat;
shape.ThreeDFormat.LightRig.Direction = LightingDirection.Top;
shape.ThreeDFormat.Material = MaterialPresetType.Flat;
shape.ThreeDFormat.ExtrusionHeight = 100;
shape.ThreeDFormat.ExtrusionColor.Color = Color.Blue;
// Save presentation
presentation.Save("3D-Shape.pptx", SaveFormat.Pptx);
}

The following is the 3D shape that we get after executing this code.

Create a 3D Shape in PowerPoint in C#

Create Gradient for 3D Shapes

You can also apply gradient effects to the shapes following the steps below.

The following code sample shows how to apply gradient effects to shapes in PowerPoint.

// Create presentation
using (Presentation presentation = new Presentation())
{
// Add a new shape
IAutoShape shape = presentation.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);
// Set text
shape.TextFrame.Text = "3D";
shape.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 64;
// Apply gradient
shape.FillFormat.FillType = FillType.Gradient;
shape.FillFormat.GradientFormat.GradientStops.Add(0, Color.Blue);
shape.FillFormat.GradientFormat.GradientStops.Add(100, Color.LightBlue);
// Apply 3D effects
shape.ThreeDFormat.Camera.CameraType = CameraPresetType.OrthographicFront;
shape.ThreeDFormat.Camera.SetRotation(20, 30, 40);
shape.ThreeDFormat.LightRig.LightType = LightRigPresetType.Flat;
shape.ThreeDFormat.LightRig.Direction = LightingDirection.Top;
shape.ThreeDFormat.Material = MaterialPresetType.Flat;
shape.ThreeDFormat.ExtrusionHeight = 100;
shape.ThreeDFormat.ExtrusionColor.Color = Color.Blue;
// Save presentation
presentation.Save("3D-Shape-Gradient.pptx", SaveFormat.Pptx);
}

The following is the 3D shape after applying the gradient effect.

Create Gradient for 3D Shapes in PowerPoint

Apply 3D Effects to an Image in PowerPoint in C#

Aspose.Slides for .NET also allows you to apply 3D effects to an image. The following are the steps to perform this operation in C#.

The following are the steps to apply 3D effects to an image in PPT using C#.

// Create presentation
using (Presentation presentation = new Presentation())
{
// Add a new shape
IAutoShape shape = presentation.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);
// Add image
shape.FillFormat.FillType = FillType.Picture;
shape.FillFormat.PictureFillFormat.Picture.Image = presentation.Images.AddImage(File.ReadAllBytes("tiger.bmp"));
shape.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;
// Apply 3D effects
shape.ThreeDFormat.Camera.CameraType = CameraPresetType.OrthographicFront;
shape.ThreeDFormat.Camera.SetRotation(20, 30, 40);
shape.ThreeDFormat.LightRig.LightType = LightRigPresetType.Flat;
shape.ThreeDFormat.LightRig.Direction = LightingDirection.Top;
shape.ThreeDFormat.Material = MaterialPresetType.Flat;
shape.ThreeDFormat.ExtrusionHeight = 100;
shape.ThreeDFormat.ExtrusionColor.Color = Color.DarkGray;
// Save presentation
presentation.Save("3D-Image.pptx", SaveFormat.Pptx);
}

The following is the resultant image that we get after applying 3D effects.

Apply 3D Effects to an Image in PowerPoint in C#

Get a Free License

You can get a free temporary license to use Aspose.Slides for .NET without evaluation limitations.

Conclusion

In this article, you have learned how to apply 3D effects in PowerPoint presentations using C#. We have covered how to create 3D text or shapes and apply 3D effects to images in PPT or PPTX presentations. In case you want to explore more about Aspose.Slides for .NET, you can visit the documentation. Also, you can post your queries to our forum.

See Also