Pictures

Picture is a special kind of drawing whose visual representation is specified by the set of color points that are usually compressed in PNG, JPEG or some other image format.

The following example shows how you can create and customize pictures and picture fills using the GemBox.Presentation API.

PowerPoint pictures created with GemBox.Presentation
Screenshot of PowerPoint pictures created with GemBox.Presentation
using System.IO;
using GemBox.Presentation;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = new PresentationDocument();

        // Create new presentation slide.
        var slide = presentation.Slides.AddNew(SlideLayoutType.Custom);

        // Create first picture from resource data.
        Picture picture = null;
        using (var stream = File.OpenRead("%#Dices.png%"))
            picture = slide.Content.AddPicture(PictureContentType.Png, stream, 2, 2, 6, 5, LengthUnit.Centimeter);

        // Create "rounded rectangle" shape.
        var shape = slide.Content.AddShape(ShapeGeometryType.RoundedRectangle, 10, 2, 8, 5, LengthUnit.Centimeter);

        // Fill shape with picture content.
        var fillFormat = shape.Format.Fill.SetPicture(picture.Fill.Data.Content);

        // Set the offset of the edges of the stretched picture fill.
        fillFormat.StretchLeft = 0.1;
        fillFormat.StretchRight = 0.4;
        fillFormat.StretchTop = 0.1;
        fillFormat.StretchBottom = 0.4;

        // Get shape outline format.
        var lineFormat = shape.Format.Outline;

        // Set shape red outline.
        lineFormat.Fill.SetSolid(Color.FromName(ColorName.Red));
        lineFormat.Width = Length.From(0.2, LengthUnit.Centimeter);

        presentation.Save("Pictures.pptx");
    }
}
Imports System.IO
Imports GemBox.Presentation

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim presentation = New PresentationDocument

        ' Create New presentation slide.
        Dim slide = presentation.Slides.AddNew(SlideLayoutType.Custom)

        ' Create first picture from resource data.
        Dim picture As Picture = Nothing
        Using stream As Stream = File.OpenRead("%#Dices.png%")
            picture = slide.Content.AddPicture(PictureContentType.Png, stream, 2, 2, 6, 5, LengthUnit.Centimeter)
        End Using

        ' Create "rounded rectangle" shape.
        Dim shape = slide.Content.AddShape(ShapeGeometryType.RoundedRectangle, 10, 2, 8, 5, LengthUnit.Centimeter)

        ' Fill shape with picture content.
        Dim fillFormat = shape.Format.Fill.SetPicture(picture.Fill.Data.Content)

        ' Set the offset of the edges of the stretched picture fill.
        fillFormat.StretchLeft = 0.1
        fillFormat.StretchRight = 0.4
        fillFormat.StretchTop = 0.1
        fillFormat.StretchBottom = 0.4

        ' Get shape outline format.
        Dim lineFormat = shape.Format.Outline

        ' Set shape red outline.
        lineFormat.Fill.SetSolid(Color.FromName(ColorName.Red))
        lineFormat.Width = Length.From(0.2, LengthUnit.Centimeter)

        presentation.Save("Pictures.pptx")
    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Presentation yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.