## ShapeRenderer class

Provides methods to render an individual [`Shape`](../../aspose.words.drawing/shape/) or [`GroupShape`](../../aspose.words.drawing/groupshape/) to a raster or vector image or to a Graphics object.

To learn more, visit the [Working with Shapes](https://docs.aspose.com/words/net/working-with-shapes/) documentation article.

```csharp
public class ShapeRenderer : NodeRendererBase
```

## Constructors

| Name | Description |
| --- | --- |
| [ShapeRenderer](shaperenderer/)(*[ShapeBase](../../aspose.words.drawing/shapebase/)*) | Initializes a new instance of this class. |

## Properties

| Name | Description |
| --- | --- |
| [BoundsInPoints](../../aspose.words.rendering/noderendererbase/boundsinpoints/) { get; } | Gets the actual bounds of the shape in points. |
| [OpaqueBoundsInPoints](../../aspose.words.rendering/noderendererbase/opaqueboundsinpoints/) { get; } | Gets the opaque bounds of the shape in points. |
| [SizeInPoints](../../aspose.words.rendering/noderendererbase/sizeinpoints/) { get; } | Gets the actual size of the shape in points. |

## Methods

| Name | Description |
| --- | --- |
| [GetBoundsInPixels](../../aspose.words.rendering/noderendererbase/getboundsinpixels/)(*float, float*) | Calculates the bounds of the shape in pixels for a specified zoom factor and resolution. |
| [GetBoundsInPixels](../../aspose.words.rendering/noderendererbase/getboundsinpixels/)(*float, float, float*) | Calculates the bounds of the shape in pixels for a specified zoom factor and resolution. |
| [GetOpaqueBoundsInPixels](../../aspose.words.rendering/noderendererbase/getopaqueboundsinpixels/)(*float, float*) | Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution. |
| [GetOpaqueBoundsInPixels](../../aspose.words.rendering/noderendererbase/getopaqueboundsinpixels/)(*float, float, float*) | Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution. |
| [GetSizeInPixels](../../aspose.words.rendering/noderendererbase/getsizeinpixels/)(*float, float*) | Calculates the size of the shape in pixels for a specified zoom factor and resolution. |
| [GetSizeInPixels](../../aspose.words.rendering/noderendererbase/getsizeinpixels/)(*float, float, float*) | Calculates the size of the shape in pixels for a specified zoom factor and resolution. |
| [RenderToScale](../../aspose.words.rendering/noderendererbase/rendertoscale/)(*Graphics, float, float, float*) | Renders the shape into a Graphics object to a specified scale. |
| [RenderToSize](../../aspose.words.rendering/noderendererbase/rendertosize/)(*Graphics, float, float, float, float*) | Renders the shape into a Graphics object to a specified size. |
| [Save](../../aspose.words.rendering/noderendererbase/save/)(*Stream, [ImageSaveOptions](../../aspose.words.saving/imagesaveoptions/)*) | Renders the shape into an image and saves into a stream. |
| [Save](../../aspose.words.rendering/noderendererbase/save/)(*Stream, [SvgSaveOptions](../../aspose.words.saving/svgsaveoptions/)*) | Renders the shape into an SVG image and saves into a stream. |
| [Save](../../aspose.words.rendering/noderendererbase/save/)(*string, [ImageSaveOptions](../../aspose.words.saving/imagesaveoptions/)*) | Renders the shape into an image and saves into a file. |
| [Save](../../aspose.words.rendering/noderendererbase/save/)(*string, [SvgSaveOptions](../../aspose.words.saving/svgsaveoptions/)*) | Renders the shape into an SVG image and saves into a file. |

## Examples

Shows how to render a shape with a Graphics object and display it using a Windows Form.

```csharp
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

ShapeForm shapeForm = new ShapeForm(new Size(1017, 840));

// Below are two ways to use the "ShapeRenderer" class to render a shape to a Graphics object.
// 1 -  Create a shape with a chart, and render it to a specific scale.
Chart chart = builder.InsertChart(ChartType.Pie, 500, 400).Chart;
chart.Series.Clear();
chart.Series.Add("Desktop Browser Market Share (Oct. 2020)",
    new[] { "Google Chrome", "Apple Safari", "Mozilla Firefox", "Microsoft Edge", "Other" },
    new[] { 70.33, 8.87, 7.69, 5.83, 7.28 });

Shape chartShape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

shapeForm.AddShapeToRenderToScale(chartShape, 0, 0, 1.5f);

// 2 -  Create a shape group, and render it to a specific size.
GroupShape group = new GroupShape(doc);
group.Bounds = new RectangleF(0, 0, 100, 100);
group.CoordSize = new Size(500, 500);

Shape subShape = new Shape(doc, ShapeType.Rectangle);
subShape.Width = 500;
subShape.Height = 500;
subShape.Left = 0;
subShape.Top = 0;
subShape.FillColor = Color.RoyalBlue;
group.AppendChild(subShape);

subShape = new Shape(doc, ShapeType.Image);
subShape.Width = 450;
subShape.Height = 450;
subShape.Left = 25;
subShape.Top = 25;
subShape.ImageData.SetImage(ImageDir + "Logo.jpg");
group.AppendChild(subShape);

builder.InsertNode(group);

GroupShape groupShape = (GroupShape)doc.GetChild(NodeType.GroupShape, 0, true);
shapeForm.AddShapeToRenderToSize(groupShape, 880, 680, 100, 100);

shapeForm.ShowDialog();
```

Shows how to render a shape with a Graphics object and display it using a Windows Form (ShapeForm).

```csharp
/// <summary>
/// Renders and displays a list of shapes.
/// </summary>
private class ShapeForm : Form
{
    public ShapeForm(Size size)
    {
        Size = size;
        mShapesToRender = new List<KeyValuePair<ShapeBase, float[]>>();
    }

    public void AddShapeToRenderToScale(ShapeBase shape, float x, float y, float scale)
    {
        mShapesToRender.Add(new KeyValuePair<ShapeBase, float[]>(shape, new[] {x, y, scale}));
    }

    public void AddShapeToRenderToSize(ShapeBase shape, float x, float y, float width, float height)
    {
        mShapesToRender.Add(new KeyValuePair<ShapeBase, float[]>(shape, new[] {x, y, width, height}));
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        foreach (KeyValuePair<ShapeBase, float[]> renderingArgs in mShapesToRender)
            if (renderingArgs.Value.Length == 3)
                RenderShapeToScale(renderingArgs.Key, renderingArgs.Value[0], renderingArgs.Value[1],
                    renderingArgs.Value[2]);
            else if (renderingArgs.Value.Length == 4)
                RenderShapeToSize(renderingArgs.Key, renderingArgs.Value[0], renderingArgs.Value[1],
                    renderingArgs.Value[2], renderingArgs.Value[3]);
    }

    private void RenderShapeToScale(ShapeBase shape, float x, float y, float scale)
    {
        ShapeRenderer renderer = new ShapeRenderer(shape);
        using (Graphics formGraphics = CreateGraphics())
        {
            renderer.RenderToScale(formGraphics, x, y, scale);
        }
    }

    private void RenderShapeToSize(ShapeBase shape, float x, float y, float width, float height)
    {
        ShapeRenderer renderer = new ShapeRenderer(shape);
        using (Graphics formGraphics = CreateGraphics())
        {
            renderer.RenderToSize(formGraphics, x, y, width, height);
        }
    }

    private readonly List<KeyValuePair<ShapeBase, float[]>> mShapesToRender;
}
```

### See Also

* class [NodeRendererBase](../noderendererbase/)
* namespace [Aspose.Words.Rendering](../../aspose.words.rendering/)
* assembly [Aspose.Words](../../)
