Formattare le forme PowerPoint in C++
Introduzione
In PowerPoint, you can add shapes to slides. Since shapes are made up of lines, you can format them by modifying or applying effects to their outlines. Additionally, you can format shapes by specifying settings that control how their interiors are filled.

Aspose.Slides for C++ provides interfaces and methods that allow you to format shapes using the same options available in PowerPoint.
Formattare le linee
Using Aspose.Slides, you can specify a custom line style for a shape. The following steps outline the procedure:
- Create an instance of the Presentation class.
- Get a reference to a slide by its index.
- Add an IAutoShape to the slide.
- Set the line style of the shape.
- Set the line width.
- Set the dash style of the line.
- Set the line color for the shape.
- Save the modified presentation as a PPTX file.
The following code demonstrates how to format a rectangle AutoShape:
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/LineDashStyle.h>
#include <DOM/LineStyle.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
// Istanziare la classe Presentation che rappresenta un file di presentazione.
auto presentation = MakeObject<Presentation>();
// Ottenere la prima diapositiva.
auto slide = presentation->get_Slide(0);
// Aggiungere una forma automatica di tipo Rectangle.
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 150, 150, 75);
// Impostare il colore di riempimento per la forma rettangolare.
shape->get_FillFormat()->set_FillType(FillType::NoFill);
// Applicare la formattazione alle linee del rettangolo.
shape->get_LineFormat()->set_Style(LineStyle::ThickThin);
shape->get_LineFormat()->set_Width(7);
shape->get_LineFormat()->set_DashStyle(LineDashStyle::Dash);
// Impostare il colore per la linea del rettangolo.
shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Blue());
// Salvare il file PPTX su disco.
presentation->Save(u"formatted_lines.pptx", SaveFormat::Pptx);
presentation->Dispose();
The result:

Applicare effetti di schizzi alle linee della forma
A sketch effect makes a shape line look hand-drawn. Use IShape::get_LineFormat to access the line settings, ILineFormat::get_SketchFormat to access the sketch settings, and ISketchFormat::set_SketchType to select a value from the LineSketchType enumeration.
The following C++ code shows how to apply a LineSketchType::Curved effect, read the explicitly assigned value, and remove the effect with LineSketchType::None:
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 200, 100);
// Access the shape's line format and its sketch format.
auto sketchFormat = shape->get_LineFormat()->get_SketchFormat();
// Apply a sketch effect.
sketchFormat->set_SketchType(LineSketchType::Curved);
// Read the sketch effect assigned directly to the shape.
auto explicitSketchType = sketchFormat->get_SketchType();
Console::WriteLine(u"Explicit sketch type: {0}", explicitSketchType);
// Remove the sketch effect.
sketchFormat->set_SketchType(LineSketchType::None);
presentation->Dispose();
The value returned by ISketchFormat::get_SketchType represents the setting assigned directly to the shape. If the line formatting can be inherited from a theme, master slide, or layout slide, use ILineFormat::GetEffective, access ILineFormatEffectiveData::get_SketchFormat, and read ISketchFormatEffectiveData::get_SketchType. The effective value reflects the formatting that is actually applied after inheritance is resolved:
auto presentation = MakeObject<Presentation>(u"presentation.pptx");
auto shape = presentation->get_Slide(0)->get_Shape(0);
auto lineFormat = shape->get_LineFormat();
auto explicitSketchType = lineFormat->get_SketchFormat()->get_SketchType();
auto effectiveLineFormat = lineFormat->GetEffective();
auto effectiveSketchType = effectiveLineFormat->get_SketchFormat()->get_SketchType();
Console::WriteLine(u"Explicit sketch type: {0}", explicitSketchType);
Console::WriteLine(u"Effective sketch type: {0}", effectiveSketchType);
presentation->Dispose();
Formattare gli stili di unione
Here are the three join type options:
- Round
- Miter
- Bevel
By default, when PowerPoint joins two lines at an angle (such as at a shape’s corner), it uses the Round setting. However, if you’re drawing a shape with sharp angles, you may prefer the Miter option.

The following C++ code demonstrates how three rectangles (as shown in the image above) were created using the Miter, Bevel, and Round join type settings:
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/LineJoinStyle.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
// Istanziare la classe Presentation che rappresenta un file di presentazione.
auto presentation = MakeObject<Presentation>();
// Ottenere la prima diapositiva.
auto slide = presentation->get_Slide(0);
// Aggiungere tre forme automatiche di tipo Rectangle.
auto shape1 = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 20, 20, 150, 75);
auto shape2 = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 210, 20, 150, 75);
auto shape3 = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 20, 135, 150, 75);
// Impostare il colore di riempimento per ciascuna forma rettangolare.
shape1->get_FillFormat()->set_FillType(FillType::Solid);
shape1->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Black());
shape2->get_FillFormat()->set_FillType(FillType::Solid);
shape2->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Black());
shape3->get_FillFormat()->set_FillType(FillType::Solid);
shape3->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Black());
// Impostare la larghezza della linea.
shape1->get_LineFormat()->set_Width(15);
shape2->get_LineFormat()->set_Width(15);
shape3->get_LineFormat()->set_Width(15);
// Impostare il colore per la linea di ciascun rettangolo.
shape1->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
shape1->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Blue());
shape2->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
shape2->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Blue());
shape3->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
shape3->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Blue());
// Impostare lo stile di unione.
shape1->get_LineFormat()->set_JoinStyle(LineJoinStyle::Miter);
shape2->get_LineFormat()->set_JoinStyle(LineJoinStyle::Bevel);
shape3->get_LineFormat()->set_JoinStyle(LineJoinStyle::Round);
// Aggiungere testo a ciascun rettangolo.
shape1->get_TextFrame()->set_Text(u"Miter Join Style");
shape2->get_TextFrame()->set_Text(u"Bevel Join Style");
shape3->get_TextFrame()->set_Text(u"Round Join Style");
// Salvare il file PPTX su disco.
presentation->Save(u"join_styles.pptx", SaveFormat::Pptx);
presentation->Dispose();
Riempimento a gradiente
In PowerPoint, Gradient Fill is a formatting option that allows you to apply a continuous blend of colors to a shape. For example, you can apply two or more colors in a way that one gradually fades into another.
Here’s how to apply a gradient fill to a shape using Aspose.Slides:
- Create an instance of the Presentation class.
- Get a reference to a slide by its index.
- Add an IAutoShape to the slide.
- Set the shape’s FillType to
Gradient. - Add your two preferred colors with defined positions using the
Addmethods of the gradient stop collection exposed by the IGradientFormat interface. - Save the modified presentation as a PPTX file.
The following C++ code demonstrates how to apply a gradient fill effect to an ellipse:
#include <DOM/FillType.h>
#include <DOM/GradientDirection.h>
#include <DOM/GradientShape.h>
#include <DOM/IAutoShape.h>
#include <DOM/IFillFormat.h>
#include <DOM/IGradientFormat.h>
#include <DOM/IGradientStopCollection.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <DOM/PresetColor.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
// Istanziare la classe Presentation che rappresenta un file di presentazione.
auto presentation = MakeObject<Presentation>();
// Ottenere la prima diapositiva.
auto slide = presentation->get_Slide(0);
// Aggiungere una forma automatica di tipo Ellipse.
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Ellipse, 50, 50, 150, 75);
// Applicare la formattazione a gradiente all'ellisse.
shape->get_FillFormat()->set_FillType(FillType::Gradient);
shape->get_FillFormat()->get_GradientFormat()->set_GradientShape(GradientShape::Linear);
// Impostare la direzione del gradiente.
shape->get_FillFormat()->get_GradientFormat()->set_GradientDirection(GradientDirection::FromCorner2);
// Aggiungere due fermate del gradiente.
shape->get_FillFormat()->get_GradientFormat()->get_GradientStops()->Add(1.0f, PresetColor::Purple);
shape->get_FillFormat()->get_GradientFormat()->get_GradientStops()->Add(0.0f, PresetColor::Red);
// Salvare il file PPTX su disco.
presentation->Save(u"gradient_fill.pptx", SaveFormat::Pptx);
presentation->Dispose();
The result:

If a gradient looks different in an exported image than it does in PowerPoint, see Scegli uno stile di rendering del gradiente. You can select a rendering style without changing the gradient fill stored in the presentation.
Riempimento a trama
In PowerPoint, Pattern Fill is a formatting option that lets you apply a two-color design—such as dots, stripes, crosshatches, or checks—to a shape. You can choose custom colors for the pattern’s foreground and background.
Aspose.Slides provides over 45 predefined pattern styles that you can apply to shapes to enhance the visual appeal of your presentations. Even after selecting a predefined pattern, you can still specify the exact colors it should use.
Here’s how to apply a pattern fill to a shape using Aspose.Slides:
- Create an instance of the Presentation class.
- Get a reference to a slide by its index.
- Add an IAutoShape to the slide.
- Set the shape’s FillType to
Pattern. - Choose a pattern style from the predefined options.
- Set the Background Color of the pattern.
- Set the Foreground Color of the pattern.
- Save the modified presentation as a PPTX file.
The following C++ code demonstrates how to apply a pattern fill to a rectangle:
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IPatternFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/PatternStyle.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
// Istanziare la classe Presentation che rappresenta un file di presentazione.
auto presentation = MakeObject<Presentation>();
// Ottenere la prima diapositiva.
auto slide = presentation->get_Slide(0);
// Aggiungere una forma automatica di tipo Rectangle.
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 150, 75);
// Impostare il tipo di riempimento su Pattern.
shape->get_FillFormat()->set_FillType(FillType::Pattern);
// Impostare lo stile del pattern.
shape->get_FillFormat()->get_PatternFormat()->set_PatternStyle(PatternStyle::Trellis);
// Impostare i colori di sfondo e di primo piano del pattern.
shape->get_FillFormat()->get_PatternFormat()->get_BackColor()->set_Color(Color::get_LightGray());
shape->get_FillFormat()->get_PatternFormat()->get_ForeColor()->set_Color(Color::get_Yellow());
// Salvare il file PPTX su disco.
presentation->Save(u"pattern_fill.pptx", SaveFormat::Pptx);
presentation->Dispose();
The result:

Riempimento con immagine
In PowerPoint, Picture Fill is a formatting option that allows you to insert an image inside a shape—effectively using the image as the shape’s background.
Here’s how to use Aspose.Slides to apply a picture fill to a shape:
- Create an instance of the Presentation class.
- Get a reference to a slide by its index.
- Add an IAutoShape to the slide.
- Set the shape’s FillType to
Picture. - Set the picture fill mode to
Tile(or another preferred mode). - Create an IPPImage object from the image you want to use.
- Pass the image to the
ISlidesPicture.set_Imagemethod. - Save the modified presentation as a PPTX file.
Let’s say we have a “lotus.png” file with the following picture:

The following C++ code demonstrates how to fill a shape with the picture:
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IFillFormat.h>
#include <DOM/IImageCollection.h>
#include <DOM/IPictureFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlidesPicture.h>
#include <DOM/PictureFillMode.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <IImage.h>
#include <Util/Images.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
// Istanziare la classe Presentation che rappresenta un file di presentazione.
auto presentation = MakeObject<Presentation>();
// Ottenere la prima diapositiva.
auto slide = presentation->get_Slide(0);
// Aggiungere una forma automatica di tipo Rectangle.
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 255, 130);
// Impostare il tipo di riempimento su Picture.
shape->get_FillFormat()->set_FillType(FillType::Picture);
// Impostare la modalità di riempimento immagine.
shape->get_FillFormat()->get_PictureFillFormat()->set_PictureFillMode(PictureFillMode::Tile);
// Caricare un'immagine e aggiungerla alle risorse della presentazione.
auto image = Images::FromFile(u"lotus.png");
auto picture = presentation->get_Images()->AddImage(image);
image->Dispose();
// Impostare l'immagine.
shape->get_FillFormat()->get_PictureFillFormat()->get_Picture()->set_Image(picture);
// Salvare il file PPTX su disco.
presentation->Save(u"picture_fill.pptx", SaveFormat::Pptx);
presentation->Dispose();
The result:

Tile Picture As Texture
If you want to set a tiled picture as a texture and customize the tiling behavior, you can use the following methods of the IPictureFillFormat interface and PictureFillFormat class:
- set_PictureFillMode: Imposta la modalità di riempimento immagine—
TileoStretch. - set_TileAlignment: Specifica l’allineamento delle tessere all’interno della forma.
- set_TileFlip: Controlla se la tessera è capovolta orizzontalmente, verticalmente o entrambe.
- set_TileOffsetX: Imposta lo spostamento orizzontale della tessera (in punti) dall’origine della forma.
- set_TileOffsetY: Imposta lo spostamento verticale della tessera (in punti) dall’origine della forma.
- set_TileScaleX: Definisce la scala orizzontale della tessera come percentuale.
- set_TileScaleY: Definisce la scala verticale della tessera come percentuale.
The following code sample shows how to add a rectangle shape with a tiled picture fill and configure tile options:
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IFillFormat.h>
#include <DOM/IImageCollection.h>
#include <DOM/IPictureFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlidesPicture.h>
#include <DOM/PictureFillMode.h>
#include <DOM/Presentation.h>
#include <DOM/RectangleAlignment.h>
#include <DOM/ShapeType.h>
#include <DOM/TileFlip.h>
#include <Export/SaveFormat.h>
#include <IImage.h>
#include <Util/Images.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
// Istanziare la classe Presentation che rappresenta un file di presentazione.
auto presentation = MakeObject<Presentation>();
// Ottenere la prima diapositiva.
auto firstSlide = presentation->get_Slide(0);
// Aggiungere una forma automatica rettangolare.
auto shape = firstSlide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 190, 95);
// Impostare il tipo di riempimento della forma su Picture.
shape->get_FillFormat()->set_FillType(FillType::Picture);
// Caricare l'immagine e aggiungerla alle risorse della presentazione.
auto sourceImage = Images::FromFile(u"lotus.png");
auto presentationImage = presentation->get_Images()->AddImage(sourceImage);
sourceImage->Dispose();
// Assegnare l'immagine alla forma.
auto pictureFillFormat = shape->get_FillFormat()->get_PictureFillFormat();
pictureFillFormat->get_Picture()->set_Image(presentationImage);
// Configurare la modalità di riempimento immagine e le proprietà di tassellazione.
pictureFillFormat->set_PictureFillMode(PictureFillMode::Tile);
pictureFillFormat->set_TileOffsetX(-32);
pictureFillFormat->set_TileOffsetY(-32);
pictureFillFormat->set_TileScaleX(50);
pictureFillFormat->set_TileScaleY(50);
pictureFillFormat->set_TileAlignment(RectangleAlignment::BottomRight);
pictureFillFormat->set_TileFlip(TileFlip::FlipBoth);
// Salvare il file PPTX su disco.
presentation->Save(u"tile.pptx", SaveFormat::Pptx);
presentation->Dispose();
The result:

Riempimento a colore solido
In PowerPoint, Solid Color Fill is a formatting option that fills a shape with a single, uniform color. This plain background color is applied without any gradients, textures, or patterns.
To apply a solid color fill to a shape using Aspose.Slides, follow these steps:
- Create an instance of the Presentation class.
- Get a reference to a slide by its index.
- Add an IAutoShape to the slide.
- Set the shape’s FillType to
Solid. - Assign your preferred fill color to the shape.
- Save the modified presentation as a PPTX file.
The following C++ code demonstrates how to apply a solid color fill to a rectangle in a PowerPoint slide:
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
// Istanziare la classe Presentation che rappresenta un file di presentazione.
auto presentation = MakeObject<Presentation>();
// Ottenere la prima diapositiva.
auto slide = presentation->get_Slide(0);
// Aggiungere una forma automatica di tipo Rectangle.
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 150, 75);
// Impostare il tipo di riempimento su Solid.
shape->get_FillFormat()->set_FillType(FillType::Solid);
// Impostare il colore di riempimento.
shape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Yellow());
// Salvare il file PPTX su disco.
presentation->Save(u"solid_color_fill.pptx", SaveFormat::Pptx);
presentation->Dispose();
The result:

Impostare la trasparenza
In PowerPoint, when you apply a solid color, gradient, picture, or texture fill to shapes, you can also set a transparency level to control the opacity of the fill. A higher transparency value makes the shape more see-through, allowing the background or underlying objects to be partially visible.
Aspose.Slides lets you set the transparency level by adjusting the alpha value in the color used for the fill. Here’s how to do it:
- Create an instance of the Presentation class.
- Get a reference to a slide by its index.
- Add an IAutoShape to the slide.
- Set the FillType to
Solid. - Use
Colorto define a color with transparency (thealphacomponent controls transparency). - Save the presentation.
The following C++ code demonstrates how to apply a transparent fill color to a rectangle:
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
// Istanziare la classe Presentation che rappresenta un file di presentazione.
auto presentation = MakeObject<Presentation>();
// Ottenere la prima diapositiva.
auto slide = presentation->get_Slide(0);
// Aggiungere una forma automatica rettangolare solida.
auto solidShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 150, 75);
// Aggiungere una forma automatica rettangolare trasparente sopra la forma solida.
auto transparentShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 80, 80, 150, 75);
transparentShape->get_FillFormat()->set_FillType(FillType::Solid);
transparentShape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::FromArgb(204, 255, 255, 0));
// Salvare il file PPTX su disco.
presentation->Save(u"shape_transparency.pptx", SaveFormat::Pptx);
presentation->Dispose();
The result:

Ruotare le forme
Aspose.Slides lets you rotate shapes in PowerPoint presentations. This can be useful when positioning visual elements with specific alignment or design needs.
To rotate a shape on a slide, follow these steps:
- Create an instance of the Presentation class.
- Get a reference to a slide by its index.
- Add an IAutoShape to the slide.
- Set the shape’s rotation property to the desired angle.
- Save the presentation.
The following C++ code demonstrates how to rotate a shape by 5 degrees:
#include <DOM/IAutoShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
// Istanziare la classe Presentation che rappresenta un file di presentazione.
auto presentation = MakeObject<Presentation>();
// Ottenere la prima diapositiva.
auto slide = presentation->get_Slide(0);
// Aggiungere una forma automatica di tipo Rectangle.
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 150, 75);
// Ruotare la forma di 5 gradi.
shape->set_Rotation(5);
// Salvare il file PPTX su disco.
presentation->Save(u"shape_rotation.pptx", SaveFormat::Pptx);
presentation->Dispose();
The result:

Aggiungere effetti di smusso 3D
Aspose.Slides allows you to apply 3D bevel effects to shapes by configuring their ThreeDFormat properties.
To add 3D bevel effects to a shape, follow these steps:
- Instantiate the Presentation class.
- Get a reference to a slide by its index.
- Add an IAutoShape to the slide.
- Configure the shape’s ThreeDFormat to define bevel settings.
- Save the presentation.
The following C++ code shows how to apply 3D bevel effects to a shape:
#include <DOM/BevelPresetType.h>
#include <DOM/CameraPresetType.h>
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/ICamera.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILightRig.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeBevel.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/IThreeDFormat.h>
#include <DOM/LightRigPresetType.h>
#include <DOM/LightingDirection.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
// Create an instance of the Presentation class.
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
// Add a shape to the slide.
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Ellipse, 50, 50, 100, 100);
shape->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Green());
shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Orange());
shape->get_LineFormat()->set_Width(2.0);
// Set the shape's ThreeDFormat properties.
shape->get_ThreeDFormat()->set_Depth(4.0);
shape->get_ThreeDFormat()->get_BevelTop()->set_BevelType(BevelPresetType::Circle);
shape->get_ThreeDFormat()->get_BevelTop()->set_Height(6);
shape->get_ThreeDFormat()->get_BevelTop()->set_Width(6);
shape->get_ThreeDFormat()->get_Camera()->set_CameraType(CameraPresetType::OrthographicFront);
shape->get_ThreeDFormat()->get_LightRig()->set_LightType(LightRigPresetType::ThreePt);
shape->get_ThreeDFormat()->get_LightRig()->set_Direction(LightingDirection::Top);
// Save the presentation as a PPTX file.
presentation->Save(u"3D_bevel_effect.pptx", SaveFormat::Pptx);
presentation->Dispose();
The result:

Aggiungere effetti di rotazione 3D
Aspose.Slides allows you to apply 3D rotation effects to shapes by configuring their ThreeDFormat properties.
To apply 3D rotation to a shape:
- Create an instance of the Presentation class.
- Get a reference to a slide by its index.
- Add an IAutoShape to the slide.
- Use the set_CameraType and set_LightType to define the 3D rotation.
- Save the presentation.
The following C++ code demonstrates how to apply 3D rotation effects to a shape:
#include <DOM/CameraPresetType.h>
#include <DOM/IAutoShape.h>
#include <DOM/ICamera.h>
#include <DOM/ILightRig.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/IThreeDFormat.h>
#include <DOM/LightRigPresetType.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
// Crea un'istanza della classe Presentation.
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 150, 75);
shape->get_TextFrame()->set_Text(u"Hello, Aspose!");
shape->get_ThreeDFormat()->set_Depth(6);
shape->get_ThreeDFormat()->get_Camera()->SetRotation(40, 35, 20);
shape->get_ThreeDFormat()->get_Camera()->set_CameraType(CameraPresetType::IsometricLeftUp);
shape->get_ThreeDFormat()->get_LightRig()->set_LightType(LightRigPresetType::Balanced);
// Salva la presentazione come file PPTX.
presentation->Save(u"3D_rotation_effect.pptx", SaveFormat::Pptx);
presentation->Dispose();
The result:

Controllare la resa in bianco e nero per le forme
The IShape::set_BlackWhiteMode method specifies how an individual shape is rendered when a presentation is viewed or processed in black-and-white mode. It does not enable black-and-white display by itself, and it does not change the shape’s fill, line, or other formatting in normal color mode.
Use a value from the BlackWhiteMode enumeration to select the desired behavior. For example, Automatic lets the rendering application choose the conversion, Gray and LightGray use gray coloring, BlackWhite uses only black and white, Black and White force a single color, Color preserves normal coloring, and Hidden omits the shape in black-and-white mode. NotDefined means that no shape-level mode is assigned.
The following C++ code creates a colored shape and makes it appear gray in black-and-white display mode:
#include <DOM/BlackWhiteMode.h>
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 200, 100);
shape->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Orange());
// Mantenere il riempimento arancione in modalità colore, ma renderizzare la forma con colorazione grigia in modalità bianco e nero.
shape->set_BlackWhiteMode(BlackWhiteMode::Gray);
presentation->Save(u"shape_black_white_mode.pptx", SaveFormat::Pptx);
presentation->Dispose();
In normal color mode, the rectangle retains its orange fill. In a black-and-white display workflow, it uses gray coloring because its mode is set to Gray. This lets you preserve a full-color slide while defining a distinct appearance for printing, previewing, or other workflows that honor the presentation’s black-and-white display settings.
Ripristinare la formattazione
The following C++ code shows how to reset the formatting of a slide and revert the position, size, and formatting of all shapes with placeholders on the LayoutSlide to their default settings:
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/enumerator_adapter.h>
#include <system/smart_ptr.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>(u"sample.pptx");
for (auto&& slide : System::IterateOver(presentation->get_Slides()))
{
// Reimposta ogni forma nella diapositiva che ha un segnaposto nel layout.
slide->Reset();
}
presentation->Save(u"reset_formatting.pptx", SaveFormat::Pptx);
presentation->Dispose();
FAQ
Does shape formatting affect the final presentation file size?
Only minimally. Embedded images and media occupy most of the file space, while shape parameters such as colors, effects, and gradients are stored as metadata and add virtually no extra size.
How can I detect shapes on a slide that share identical formatting so I can group them?
Compare each shape’s key formatting properties—fill, line, and effect settings. If all corresponding values match, treat their styles as identical and logically group those shapes, which simplifies later style management.
Can I save a set of custom shape styles to a separate file for reuse in other presentations?
Yes. Store sample shapes with the desired styles in a template slide deck or a .POTX template file. When creating a new presentation, open the template, clone the styled shapes you need, and re‑apply their formatting wherever required.