Formátování tvarů PowerPointu v .NET

Úvod

Formátujte tvary v PowerPointu úpravou jejich obrysů, výplní a efektů. Aspose.Slides for .NET vám umožňuje tyto nastavení řídit programově, včetně průhlednosti, otáčení a 3D formátování.

Možnosti formátování tvaru v PowerPointu

Aspose.Slides for .NET poskytuje rozhraní a vlastnosti, které vám umožňují formátovat tvary pomocí stejných možností, jaké jsou k dispozici v PowerPointu.

Formátování čar

Použijte IShape.LineFormat k řízení obrysu tvaru. Tento příklad vytvoří nevyplněný obdélník s modrým, čárkovaným obrysem. ILineFormat.Style vybírá spojenou čáru tlustá‑tenká, zatímco ILineFormat.Width nastavuje její šířku na 7 bodů a ILineFormat.DashStyle vybírá vzor čáry.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 75);
shape.FillFormat.FillType = FillType.NoFill;
shape.LineFormat.Style = LineStyle.ThickThin;
shape.LineFormat.Width = 7;
shape.LineFormat.DashStyle = LineDashStyle.Dash;
shape.LineFormat.FillFormat.FillType = FillType.Solid;
shape.LineFormat.FillFormat.SolidFillColor.Color = Color.Blue;

presentation.Save("formatted_lines.pptx", SaveFormat.Pptx);

Výsledek:

Formátované čáry v prezentaci

Nastavení vlastních vzorů čárek

Použijte ILineFormat.CustomDashPattern v situacích, kdy předdefinované styly čar neposkytují požadované délky čárek a mezer, například pro firemní obrysy nebo technické diagramy. Přiřazením vzoru se automaticky nastaví ILineFormat.DashStyle na LineDashStyle.Custom.

Pole vstupů střídá délky čárek a mezer, začíná čárkou. Každá hodnota je násobkem šířky čáry: { 4, 2 } při šířce 3 body vytvoří čáru dlouhou 12 bodů následovanou mezerou 6 bodů. Používejte páry konečných, nezáporných hodnot pro definování kompletních úseků čárek‑a‑mezer. Příklad používá kladné hodnoty, aby byly všechny čárky a mezery viditelné.

Tento příklad vytvoří pět modrých čar se stejnou délkou a plochými konci. První tři porovnávají vzory při šířce 3 body. Čtvrtá zopakuje první vzor při dvojnásobné šířce, čímž zdvojnásobí jak délku čáry, tak mezery. Pátá přepne z vlastního vzoru na plnou čáru.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
presentation.SlideSize.SetSize(600, 300, SlideSizeScaleType.DoNotScale);
var slide = presentation.Slides[0];

var patterns = new[]
{
    new float[] { 4, 2 },
    new float[] { 1, 2 },
    new float[] { 6, 2, 1, 2 },
    new float[] { 4, 2 },
    new float[] { 4, 2 }
};

for (var i = 0; i < patterns.Length; i++)
{
    var line = slide.Shapes.AddAutoShape(ShapeType.Line, 50, 50 + i * 50, 500, 0);
    line.LineFormat.Width = i == 3 ? 6 : 3;
    line.LineFormat.FillFormat.FillType = FillType.Solid;
    line.LineFormat.FillFormat.SolidFillColor.Color = Color.DarkBlue;
    line.LineFormat.CapStyle = LineCapStyle.Flat;
    line.LineFormat.BeginArrowheadStyle = LineArrowheadStyle.None;
    line.LineFormat.EndArrowheadStyle = LineArrowheadStyle.None;
    line.LineFormat.CustomDashPattern = patterns[i];
}

// Return the last line to a solid style.
slide.Shapes[4].LineFormat.DashStyle = LineDashStyle.Solid;

presentation.Save("custom_dash_patterns.pptx", SaveFormat.Pptx);

Chcete‑li se vrátit k předdefinovanému čárkovanému stylu, přiřaďte LineDashStyle.Dash k ILineFormat.DashStyle. Vybraný styl řídí vzhled čáry.

Výsledek v PowerPointu, shora dolů: {4, 2}, 3 pt; {1, 2}, 3 pt; {6, 2, 1, 2}, 3 pt; {4, 2}, 6 pt; a Solid, 3 pt.

Tři vlastní vzory čárek, širší čára používající první vzor a plná čára v PowerPointu

Nastavení koncových stylů čar

Použijte ILineFormat.CapStyle pro nastavení konců otevřené čáry. Výčtová sada LineCapStyle poskytuje tři explicitní styly konců:

  • Flat: Tah končí u koncového bodu.
  • Round: Polokruhový konec přesahuje koncový bod o polovinu šířky čáry.
  • Square: Čtvercový konec přesahuje koncový bod o polovinu šířky čáry.

Výčet také obsahuje NotDefined, což znamená, že žádný styl konce není explicitně přiřazen.

Konce se liší od šipek, které přidávají symboly na konce čar, a od spojů, které řídí rohy mezi segmenty čar. Tento příklad zakáže šipky pomocí ILineFormat.BeginArrowheadStyle a ILineFormat.EndArrowheadStyle, aby byly porovnávány jen tvary konců.

Následující příklad vytvoří tři jinak identické vodorovné čáry o šířce 20 bodů. Shora dolů používají ploché, kulaté a čtvercové konce. Jejich koncové body mají stejné vodorovné souřadnice; kulaté a čtvercové konce přesahují 10 bodů za každý koncový bod.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
presentation.SlideSize.SetSize(500, 240, SlideSizeScaleType.DoNotScale);
var slide = presentation.Slides[0];

var capStyles = new[] { LineCapStyle.Flat, LineCapStyle.Round, LineCapStyle.Square };

for (var i = 0; i < capStyles.Length; i++)
{
    var line = slide.Shapes.AddAutoShape(ShapeType.Line, 100, 50 + i * 70, 300, 0);
    line.LineFormat.Width = 20;
    line.LineFormat.FillFormat.FillType = FillType.Solid;
    line.LineFormat.FillFormat.SolidFillColor.Color = Color.DarkBlue;
    line.LineFormat.DashStyle = LineDashStyle.Solid;
    line.LineFormat.CapStyle = capStyles[i];
    line.LineFormat.BeginArrowheadStyle = LineArrowheadStyle.None;
    line.LineFormat.EndArrowheadStyle = LineArrowheadStyle.None;
}

presentation.Save("line_caps.pptx", SaveFormat.Pptx);

Výsledek v PowerPointu, shora dolů: Flat, Round a Square.

Plochý, kulatý a čtvercový konec na identických silných čarách v PowerPointu

Použití skicových efektů na čáry tvarů

Skicový efekt způsobí, že čára tvaru vypadá ručně kresleně. Použijte IShape.LineFormat pro přístup k nastavení čáry, ILineFormat.SketchFormat pro přístup k nastavení skici a ISketchFormat.SketchType pro výběr hodnoty z výčtu LineSketchType.

Následující kód v C# ukazuje, jak použít efekt LineSketchType.Curved, přečíst explicitně přiřazenou hodnotu a odstranit efekt pomocí LineSketchType.None:

using System;
using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 200, 100);

var sketchFormat = shape.LineFormat.SketchFormat;
sketchFormat.SketchType = LineSketchType.Curved;
var explicitSketchType = sketchFormat.SketchType;
Console.WriteLine($"Explicit sketch type: {explicitSketchType}");
sketchFormat.SketchType = LineSketchType.None;

Hodnota vrácená ISketchFormat.SketchType představuje nastavení přiřazené přímo tvaru. Pokud může být formátování čáry zděděno z motivu, hlavního snímku nebo rozvržení snímku, použijte ILineFormat.GetEffective, přistupte k ILineFormatEffectiveData.SketchFormat a přečtěte ISketchFormatEffectiveData.SketchType. Efektivní hodnota odráží formátování, které je skutečně aplikováno po vyřešení dědičnosti. Tento příklad vyžaduje existující prezentaci s alespoň jedním tvarem na prvním snímku a vypíše obě hodnoty:

using System;
using Aspose.Slides;

using var presentation = new Presentation("presentation.pptx");
var shape = presentation.Slides[0].Shapes[0];

var lineFormat = shape.LineFormat;
var explicitSketchType = lineFormat.SketchFormat.SketchType;
var effectiveLineFormat = lineFormat.GetEffective();
var effectiveSketchType = effectiveLineFormat.SketchFormat.SketchType;

Console.WriteLine($"Explicit sketch type: {explicitSketchType}");
Console.WriteLine($"Effective sketch type: {effectiveSketchType}");

Formátování stylů spojů

Zde jsou tři možnosti typu spoje:

  • Round
  • Miter
  • Bevel

Styl spoje řídí, jak se dva úseky obrysu setkají v rohu. Použijte Round pro zaoblené rohy, Miter pro ostré rohy nebo Bevel pro zploštělé rohy.

Styl spoje v prezentaci

Tento příklad vytvoří tři černé obdélníky s modrými obrysy o šířce 15 bodů. Nastaví ILineFormat.JoinStyle na hodnoty miter, bevel a round z výčtu LineJoinStyle, aby porovnal, jak jsou rohy vykresleny.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var miterShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 150, 75);
var bevelShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 210, 20, 150, 75);
var roundShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 135, 150, 75);

miterShape.FillFormat.FillType = FillType.Solid;
miterShape.FillFormat.SolidFillColor.Color = Color.Black;
bevelShape.FillFormat.FillType = FillType.Solid;
bevelShape.FillFormat.SolidFillColor.Color = Color.Black;
roundShape.FillFormat.FillType = FillType.Solid;
roundShape.FillFormat.SolidFillColor.Color = Color.Black;

miterShape.LineFormat.Width = 15;
bevelShape.LineFormat.Width = 15;
roundShape.LineFormat.Width = 15;

miterShape.LineFormat.FillFormat.FillType = FillType.Solid;
miterShape.LineFormat.FillFormat.SolidFillColor.Color = Color.Blue;
bevelShape.LineFormat.FillFormat.FillType = FillType.Solid;
bevelShape.LineFormat.FillFormat.SolidFillColor.Color = Color.Blue;
roundShape.LineFormat.FillFormat.FillType = FillType.Solid;
roundShape.LineFormat.FillFormat.SolidFillColor.Color = Color.Blue;

miterShape.LineFormat.JoinStyle = LineJoinStyle.Miter;
bevelShape.LineFormat.JoinStyle = LineJoinStyle.Bevel;
roundShape.LineFormat.JoinStyle = LineJoinStyle.Round;

miterShape.TextFrame.Text = "Miter Join Style";
bevelShape.TextFrame.Text = "Bevel Join Style";
roundShape.TextFrame.Text = "Round Join Style";

presentation.Save("join_styles.pptx", SaveFormat.Pptx);

Omezení miterových spojů u ostrých rohů

Použijte ILineFormat.MiterLimit spolu s ILineFormat.JoinStyle nastaveným na LineJoinStyle.Miter pro omezení, jak daleko může ostrý roh vystupovat.

Limit je poměr vzdálenosti mezi vnitřním a vnějším rohem spoje k šířce čáry. Například hodnota 8 dovolí délku miteru až osminásobek šířky čáry; není to měření v bodech. Pokud by roh překročil limit, PowerPoint použije zploštělý spoj v tomto rohu. Větší limit umožňuje ostřejší špičky. Nastavení ovlivňuje jen miterové spoje a změna nemá viditelný efekt, když roh zůstane v obou limitech.

Tento příklad vytvoří dva identické, nevyplněné trojúhelníky s obrysy o šířce 20 bodů. Levý trojúhelník používá limit 2 a pravý 8. Každý trojúhelník má šířku 80 bodů a výšku 160 bodů, což dává jeho hornímu rohu poměr délka‑miteru k šířce čáry přibližně 4,12. Výsledkem je, že PowerPoint zploští levý vrchol a zachová pravý.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
presentation.SlideSize.SetSize(500, 320, SlideSizeScaleType.DoNotScale);
var slide = presentation.Slides[0];

var miterLimits = new[] { 2f, 8f };

for (var i = 0; i < miterLimits.Length; i++)
{
    var triangle = slide.Shapes.AddAutoShape(ShapeType.Triangle, 90 + i * 240, 110, 80, 160);
    triangle.FillFormat.FillType = FillType.NoFill;
    triangle.LineFormat.Width = 20;
    triangle.LineFormat.FillFormat.FillType = FillType.Solid;
    triangle.LineFormat.FillFormat.SolidFillColor.Color = Color.DarkBlue;
    triangle.LineFormat.JoinStyle = LineJoinStyle.Miter;
    triangle.LineFormat.MiterLimit = miterLimits[i];
}

presentation.Save("miter_limits.pptx", SaveFormat.Pptx);

Výsledek v PowerPointu: Miter limit 2 vlevo a miter limit 8 vpravo.

Zploštělý vrchol s limitem miter 2 a špičatý vrchol s limitem miter 8 v PowerPointu

Gradientní výplň

Gradientní výplň míchá barvy napříč tvarem. Tento příklad vyplní elipsu lineárním gradientem pod úhlem 45 stupňů od červené po fialovou pomocí IFillFormat.GradientFormat. Metoda IGradientStopCollection.Add umístí barevné zastávky na 0 a 1, na začátek a konec gradientu. Vymazání existujících zastávek zajistí, že budou použity jen tyto dvě barvy.

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Ellipse, 50, 50, 150, 75);
shape.FillFormat.FillType = FillType.Gradient;
shape.FillFormat.GradientFormat.GradientShape = GradientShape.Linear;
shape.FillFormat.GradientFormat.LinearGradientAngle = 45;
shape.FillFormat.GradientFormat.GradientStops.Clear();
shape.FillFormat.GradientFormat.GradientStops.Add(1.0f, PresetColor.Purple);
shape.FillFormat.GradientFormat.GradientStops.Add(0.0f, PresetColor.Red);

presentation.Save("gradient_fill.pptx", SaveFormat.Pptx);

Výsledek:

Elipsa s gradientní výplní

Pokud se gradient v exportovaném obrázku liší od toho v PowerPointu, podívejte se na Choose a Gradient Rendering Style. Můžete vybrat styl vykreslování, aniž byste změnili gradientní výplň uloženou v prezentaci.

Nastavení úhlu lineárního gradientu

Použijte IGradientFormat.LinearGradientAngle pro řízení orientace výplně GradientShape.Linear. Úhel se měří ve stupních a zvyšuje se po směru hodinových ručiček: 0 běží zleva doprava, 90 shora dolů, 180 zprava doleva a 270 zdola nahoru. Zlomkové úhly jsou podporovány. Konečné úhly mimo rozsah [0, 360) se normalizují na jednu otáčku; například -45 se stane 315 a 360 se stane 0.

Tento příklad vytvoří šest obdélníků se stejnými červenými, zelenými a modrými zastávkami na pozicích 0, 0.5 a 1. Škálování je vypnuto, aby byl úhel srovnáván nezávisle na proporcích obdélníků. Úhly, zleva doprava, jsou 0, 45 a 90 v první řadě a 135, 180 a 270 ve druhé řadě.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
presentation.SlideSize.SetSize(720, 400, SlideSizeScaleType.DoNotScale);
var slide = presentation.Slides[0];

var angles = new float[] { 0, 45, 90, 135, 180, 270 };

for (var i = 0; i < angles.Length; i++)
{
    var x = 30 + (i % 3) * 230;
    var y = 30 + (i / 3) * 190;

    var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, x, y, 200, 150);
    shape.LineFormat.FillFormat.FillType = FillType.NoFill;
    shape.FillFormat.FillType = FillType.Gradient;

    var gradient = shape.FillFormat.GradientFormat;
    gradient.GradientShape = GradientShape.Linear;
    gradient.GradientStops.Clear();
    gradient.GradientStops.Add(0f, Color.Red);
    gradient.GradientStops.Add(0.5f, Color.Lime);
    gradient.GradientStops.Add(1f, Color.Blue);
    gradient.LinearGradientScaled = NullableBool.False;
    gradient.LinearGradientAngle = angles[i];
}

presentation.Save("linear_gradient_angles.pptx", SaveFormat.Pptx);

Výsledek v PowerPointu:

Lineární gradienty při 0°, 45° a 90° v horní řadě a 135°, 180° a 270° ve spodní řadě

Škálování lineárního gradientu s tvarem

IGradientFormat.LinearGradientScaled přijímá hodnotu NullableBool. Nastavte ji explicitně na False, aby se geometrický úhel gradientu zachoval při změně proporcí tvaru, nebo na True, aby se gradient škáloval spolu se šířkou a výškou tvaru. Při povoleném škálování se viditelný úhel může lišit od přiřazeného úhlu u nesčtvercového tvaru.

Následující příklad používá úhel 45 stupňů a stejné barevné zastávky jako při porovnávání úhlů. Levý sloupec používá False; pravý sloupec používá True. Každý sloupec obsahuje široký obdélník nad vysokým obdélníkem. Oba začínají se stejnými širokými rozměry; změna šířky a výšky druhého obdélníku demonstruje, jak se výplň přizpůsobuje změně velikosti bez změny nastavení gradientu.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
presentation.SlideSize.SetSize(720, 460, SlideSizeScaleType.DoNotScale);
var slide = presentation.Slides[0];

var scalingOptions = new[] { NullableBool.False, NullableBool.True };

for (var column = 0; column < scalingOptions.Length; column++)
{
    for (var row = 0; row < 2; row++)
    {
        var x = 30 + column * 360;
        var y = row == 0 ? 30 : 150;
        
        var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, x, y, 300, 90);
        shape.LineFormat.FillFormat.FillType = FillType.NoFill;
        shape.FillFormat.FillType = FillType.Gradient;

        var gradient = shape.FillFormat.GradientFormat;
        gradient.GradientShape = GradientShape.Linear;
        gradient.GradientStops.Clear();
        gradient.GradientStops.Add(0f, Color.Red);
        gradient.GradientStops.Add(0.5f, Color.Lime);
        gradient.GradientStops.Add(1f, Color.Blue);
        gradient.LinearGradientAngle = 45;
        gradient.LinearGradientScaled = scalingOptions[column];

        if (row == 1)
        {
            shape.Width = 90;
            shape.Height = 280;
        }
    }
}

presentation.Save("linear_gradient_scaling.pptx", SaveFormat.Pptx);

Výsledek v PowerPointu, s vypnutým škálováním vlevo a povoleným vpravo:

Široké a vysoké obdélníky s 45° gradientem, s LinearGradientScaled False vlevo a True vpravo

Při vypnutém škálování si šikmé barevné pásy uchovají stejnou orientaci v obou obdélnících. Při povoleném škálování se pásy natáhnou spolu s proporcemi tvaru. Toto pomáhá reprodukovat gradient šablony při adaptaci tvaru na jinou velikost. U čtverce povolení škálování nemění vzhled tohoto 45‑stupňového gradientu.

Oba nastavení – úhel i škálování – se vztahují jen na lineární gradienty. Nekontrolují výplně GradientShape.Radial or GradientShape.Rectangle.

Kombinace úhlu se směrem gradientu

IGradientFormat.GradientDirection vybírá styl gradientu z výčtu GradientDirection; není to náhrada za číselný úhel. Pro lineární gradient mohou styly rohu změnit oblast, nad kterou jsou barvy rozloženy, aniž by změnily LinearGradientAngle. Při porovnávání úhlů nebo škálování nechte směr beze změny.

Následující příklad aplikuje stejná nastavení v opačném pořadí. Oba obdélníky mají stejný vzhled: přiřazení směru před nebo po nastavení úhlu nemění výsledek.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

for (var i = 0; i < 2; i++)
{
    var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 30, 30 + i * 140, 320, 100);
    shape.LineFormat.FillFormat.FillType = FillType.NoFill;
    shape.FillFormat.FillType = FillType.Gradient;

    var gradient = shape.FillFormat.GradientFormat;
    gradient.GradientShape = GradientShape.Linear;
    gradient.GradientStops.Clear();
    gradient.GradientStops.Add(0f, Color.Red);
    gradient.GradientStops.Add(0.5f, Color.Lime);
    gradient.GradientStops.Add(1f, Color.Blue);
    gradient.LinearGradientScaled = NullableBool.True;

    if (i == 0)
    {
        gradient.GradientDirection = GradientDirection.FromCorner1;
        gradient.LinearGradientAngle = 30;
    }
    else
    {
        gradient.LinearGradientAngle = 30;
        gradient.GradientDirection = GradientDirection.FromCorner1;
    }
}

presentation.Save("linear_gradient_direction.pptx", SaveFormat.Pptx);

Pattern Fill

Pattern fill applies a two‑color design, such as dots, stripes, or checks. This example uses IPatternFormat.PatternStyle to select a trellis pattern. IPatternFormat.BackColor supplies the light gray background, and IPatternFormat.ForeColor supplies the yellow pattern color.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 75);
shape.FillFormat.FillType = FillType.Pattern;
shape.FillFormat.PatternFormat.PatternStyle = PatternStyle.Trellis;
shape.FillFormat.PatternFormat.BackColor.Color = Color.LightGray;
shape.FillFormat.PatternFormat.ForeColor.Color = Color.Yellow;

presentation.Save("pattern_fill.pptx", SaveFormat.Pptx);

Výsledek:

Obdélník s pattern výplní

Picture Fill

A picture fill uses an image inside a shape. This example requires a local image and uses Images.FromFile to load it into the presentation’s image collection. Setting IPictureFillFormat.PictureFillMode to the tiled mode repeats the image within the rectangle. The source image used here is shown below:

The lotus picture

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 255, 130);
shape.FillFormat.FillType = FillType.Picture;
shape.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Tile;

using var image = Images.FromFile("lotus.png");
var presentationImage = presentation.Images.AddImage(image);
shape.FillFormat.PictureFillFormat.Picture.Image = presentationImage;

presentation.Save("picture_fill.pptx", SaveFormat.Pptx);

Výsledek:

Tvar s picture výplní

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 properties of the IPictureFillFormat interface and PictureFillFormat class:

  • PictureFillMode: Sets the picture fill mode—either Tile or Stretch.
  • TileAlignment: Specifies the alignment of the tiles within the shape.
  • TileFlip: Controls whether the tile is flipped horizontally, vertically, or both.
  • TileOffsetX: Sets the horizontal offset of the tile (in points) from the shape’s origin.
  • TileOffsetY: Sets the vertical offset of the tile (in points) from the shape’s origin.
  • TileScaleX: Defines the horizontal scale of the tile as a percentage.
  • TileScaleY: Defines the vertical scale of the tile as a percentage.

This example requires a local image and configures IPictureFillFormat to repeat it at 50% of its original size. Offsets of −32 points shift the tiles horizontally and vertically; bottom‑right alignment and flipping in both directions determine how the repeated texture is arranged.

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var firstSlide = presentation.Slides[0];

var shape = firstSlide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 190, 95);
shape.FillFormat.FillType = FillType.Picture;

using var sourceImage = Images.FromFile("lotus.png");
var presentationImage = presentation.Images.AddImage(sourceImage);

var pictureFillFormat = shape.FillFormat.PictureFillFormat;
pictureFillFormat.Picture.Image = presentationImage;
pictureFillFormat.PictureFillMode = PictureFillMode.Tile;
pictureFillFormat.TileOffsetX = -32;
pictureFillFormat.TileOffsetY = -32;
pictureFillFormat.TileScaleX = 50;
pictureFillFormat.TileScaleY = 50;
pictureFillFormat.TileAlignment = RectangleAlignment.BottomRight;
pictureFillFormat.TileFlip = TileFlip.FlipBoth;

presentation.Save("tile.pptx", SaveFormat.Pptx);

Výsledek:

Možnosti tile

Solid Color Fill

A solid fill gives a shape a single, uniform color. This example sets IFillFormat.FillType to the solid fill mode and assigns yellow through IFillFormat.SolidFillColor, then saves the rectangle in a presentation.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 75);
shape.FillFormat.FillType = FillType.Solid;
shape.FillFormat.SolidFillColor.Color = Color.Yellow;

presentation.Save("solid_color_fill.pptx", SaveFormat.Pptx);

Výsledek:

Tvar se solid color výplní

Use the Slide Background as a Shape Fill

Use IAutoShape.UseBackgroundFill when a shape should match the slide background, for example in a presentation template. Set IFillFormat.FillType to FillType.NotDefined first to remove any explicit fill. With this combination, the shape uses the slide background instead of its style fill. Enabling the flag alone does not remove an existing explicit fill.

This differs from FillType.NoFill: background fill covers objects behind the shape with the corresponding area of the slide background, while no fill leaves those objects visible. A gradient remains aligned with the slide rather than restarting inside each shape.

The following example creates a master background inherited by the slide and places a magenta band behind three rectangles. The left rectangle uses the background, the middle rectangle has no fill, and the right rectangle switches from background fill to an explicit orange fill.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
presentation.SlideSize.SetSize(720, 400, SlideSizeScaleType.DoNotScale);
var slide = presentation.Slides[0];

// Zdědit gradient z hlavního snímku.
slide.Background.Type = BackgroundType.NotDefined;
slide.LayoutSlide.Background.Type = BackgroundType.NotDefined;
var background = slide.LayoutSlide.MasterSlide.Background;
background.Type = BackgroundType.OwnBackground;
background.FillFormat.FillType = FillType.Gradient;
var gradient = background.FillFormat.GradientFormat;
gradient.GradientShape = GradientShape.Linear;
gradient.LinearGradientAngle = 0;
gradient.GradientStops.Clear();
gradient.GradientStops.Add(0, Color.DarkBlue);
gradient.GradientStops.Add(1, Color.LightSkyBlue);

// Nejdříve přidejte tento objekt, aby se zobrazil za obdélníky.
var band = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 25, 150, 670, 100);
band.FillFormat.FillType = FillType.Solid;
band.FillFormat.SolidFillColor.Color = Color.Magenta;
band.LineFormat.FillFormat.FillType = FillType.NoFill;

var backgroundShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 100, 160, 200);
backgroundShape.FillFormat.FillType = FillType.NotDefined;
backgroundShape.UseBackgroundFill = true;

var noFillShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 280, 100, 160, 200);
noFillShape.FillFormat.FillType = FillType.NoFill;

var explicitShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 510, 100, 160, 200);
explicitShape.FillFormat.FillType = FillType.NotDefined;
explicitShape.UseBackgroundFill = true;

// Zakázat výplň pozadí před aplikací explicitní výplně.
explicitShape.UseBackgroundFill = false;
explicitShape.FillFormat.FillType = FillType.Solid;
explicitShape.FillFormat.SolidFillColor.Color = Color.Orange;

presentation.Save("background_fill.pptx", SaveFormat.Pptx);

Výsledek, zleva doprava: background fill, no fill, and explicit fill. The magenta band is hidden by the left and right rectangles but remains visible through the middle rectangle.

Background fill, no fill, and explicit orange fill over a magenta band

The same behavior applies to a background defined directly on the slide or inherited from a layout. The shape uses the slide’s resolved background; the example leaves both the slide and layout backgrounds undefined so the master supplies it.

Set Transparency

For a solid fill, the color’s alpha component controls opacity: 0 is fully transparent and 255 is fully opaque. This example uses an alpha value of 128 for a yellow rectangle, making it approximately 50% transparent so the rectangle underneath remains visible. The color is assigned through IFillFormat.SolidFillColor.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

const int alpha = 128;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var solidShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 75);

var transparentShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 80, 80, 150, 75);
transparentShape.FillFormat.FillType = FillType.Solid;
transparentShape.FillFormat.SolidFillColor.Color = Color.FromArgb(alpha, Color.Yellow);

presentation.Save("shape_transparency.pptx", SaveFormat.Pptx);

Výsledek:

The transparent shape

Rotate Shapes

Use IShape.Rotation to rotate a shape in the slide plane. The angle is measured in degrees; this example rotates a rectangle 5 degrees clockwise and saves the presentation.

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 75);
shape.Rotation = 5;

presentation.Save("shape_rotation.pptx", SaveFormat.Pptx);

Výsledek:

The shape rotation

Add 3D Bevel Effects

Use IShape.ThreeDFormat to give a shape depth and beveled edges. This example creates a green ellipse with an orange outline, sets IThreeDFormat.Depth to 4 points, and applies a circular top bevel with a width and height of 6 points through IThreeDFormat.BevelTop. A front‑facing orthographic camera and three‑point lighting make the bevel visible.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Ellipse, 50, 50, 100, 100);
shape.FillFormat.FillType = FillType.Solid;
shape.FillFormat.SolidFillColor.Color = Color.Green;
shape.LineFormat.FillFormat.FillType = FillType.Solid;
shape.LineFormat.FillFormat.SolidFillColor.Color = Color.Orange;
shape.LineFormat.Width = 2.0;
shape.ThreeDFormat.Depth = 4;
shape.ThreeDFormat.BevelTop.BevelType = BevelPresetType.Circle;
shape.ThreeDFormat.BevelTop.Height = 6;
shape.ThreeDFormat.BevelTop.Width = 6;
shape.ThreeDFormat.Camera.CameraType = CameraPresetType.OrthographicFront;
shape.ThreeDFormat.LightRig.LightType = LightRigPresetType.ThreePt;
shape.ThreeDFormat.LightRig.Direction = LightingDirection.Top;

presentation.Save("3D_bevel_effect.pptx", SaveFormat.Pptx);

Výsledek:

The 3D bevel effect

Add 3D Rotation Effects

A shape’s 3D view is controlled by its camera settings. This example uses ICamera.SetRotation with latitude, longitude, and revolution angles of 40, 35, and 20 degrees, respectively. It selects an isometric camera through ICamera.CameraType and balanced lighting through ILightRig.LightType, then saves the formatted rectangle.

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 75);
autoShape.TextFrame.Text = "Hello, Aspose!";
autoShape.ThreeDFormat.Camera.CameraType = CameraPresetType.IsometricLeftUp;
autoShape.ThreeDFormat.Camera.SetRotation(40, 35, 20);
autoShape.ThreeDFormat.LightRig.LightType = LightRigPresetType.Balanced;

presentation.Save("3D_rotation_effect.pptx", SaveFormat.Pptx);

Výsledek:

The 3D rotation effect

Control Black-and-White Rendering for Shapes

The IShape.BlackWhiteMode property 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.

This example creates an orange rectangle and sets IShape.BlackWhiteMode to gray. The saved shape retains its orange fill for normal color display and requests gray coloring from applications that honor black‑and‑white display settings:

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 200, 100);
shape.FillFormat.FillType = FillType.Solid;
shape.FillFormat.SolidFillColor.Color = Color.Orange;
shape.BlackWhiteMode = BlackWhiteMode.Gray;

presentation.Save("shape_black_white_mode.pptx", SaveFormat.Pptx);

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.

Reset Formatting

Use ISlide.Reset to restore the position, size, and formatting of slide placeholders from their corresponding layout placeholders. This example requires an existing presentation with layout‑linked placeholders and resets every slide before saving. Shapes without corresponding layout placeholders are not reset.

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
foreach (var slide in presentation.Slides)
{
    slide.Reset();
}

presentation.Save("reset_formatting.pptx", SaveFormat.Pptx);

FAQ

Does shape formatting affect the final presentation file size?

Colors, line styles, and effect settings generally add little data compared with embedded images and media. Picture fills can increase the file size because their images are stored in the presentation.

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 reapply their formatting wherever required.