Click or drag to resize

Picture Class

Represents a picture.
Inheritance Hierarchy

Namespace:  SautinSoft.Document.Drawing
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 3.7.4.3 (3.7.4.3)
Syntax
public sealed class Picture : Shape

The Picture type exposes the following members.

Constructors
  NameDescription
Public methodCode examplePicture(DocumentCore, String)
Initializes a new instance of the Picture class.
Public methodCode examplePicture(DocumentCore, Layout, String)
Initializes a new instance of the Picture class.
Public methodCode examplePicture(DocumentCore, Stream, PictureFormat)
Initializes a new instance of the Picture class.
Public methodCode examplePicture(DocumentCore, Layout, Stream, PictureFormat)
Initializes a new instance of the Picture class.
Top
Properties
  NameDescription
Public propertyCharacterFormat
Gets or sets the character format.
(Inherited from ShapeBase.)
Public propertyContent
Gets the ContentRange of the current element.
(Inherited from Element.)
Public propertyDocument
Gets the owner document.
(Inherited from Element.)
Public propertyCode exampleElementType
Gets the ElementType of this element instance.
(Overrides ShapeElementType.)
Public propertyFill
Gets the Brush that specifies how the shape's interior is filled.
(Inherited from ShapeBase.)
Public propertyFlipOrientation
Gets or sets the orientation of a shape.
(Inherited from ShapeBase.)
Public propertyCode exampleGeometry
Gets a shape's geometry.
(Inherited from Shape.)
Public propertyCode exampleImageData
Gets an image data.
Public propertyIsTopLevel
Returns true if this shape is not a child of a group shape.
(Inherited from ShapeBase.)
Public propertyLayout
Gets or sets the ShapeBase layout (position and size).
(Inherited from ShapeBase.)
Public propertyNextSibling
Gets the next Element sibling.
(Inherited from Element.)
Public propertyOutline
Gets the Pen that specifies the shape's outline.
(Inherited from Shape.)
Public propertyParent
Gets the parent of this element instance.
(Inherited from Element.)
Public propertyParentCollection
Gets the InlineCollection that contains this Inline instance.
(Inherited from Inline.)
Public propertyParentGroup
Gets the parent group shape.
(Inherited from ShapeBase.)
Public propertyPreviuosSibling
Gets the previous Element sibling.
(Inherited from Element.)
Public propertyRotation
Gets or sets the angle (in degrees) that a shape is rotated. Positive value corresponds to clockwise rotation angle.
(Inherited from ShapeBase.)
Public propertyCode exampleText
Gets a shape's text.
(Inherited from Shape.)
Top
Methods
  NameDescription
Public methodClone
Clones this element instance.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodCode exampleGetChildElements(Boolean)
Gets the child elements.
(Inherited from Element.)
Public methodCode exampleGetChildElements(Boolean, ElementType)
Gets the child elements filtered by ElementType.
(Inherited from Element.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implementationPrivate propertyIContentElementContent
Gets a sequence of ElementCollections that are contained under this IContentElement.
(Inherited from Shape.)
Top
Examples
How to add Pictures into a document in C#
using SautinSoft.Document;
using SautinSoft.Document.Drawing;

namespace Sample
{
    class Sample
    {

        static void Main(string[] args)
        {
            AddPictures();
        }

        /// <summary>
        /// How to add pictures into a document. 
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/add-pictures.php
        /// </remarks>
        public static void AddPictures()
        {
            string documentPath = @"Pictures.docx";
            string pictPath = @"..\..\image1.jpg";

            // Let's create a simple document.
            DocumentCore dc = new DocumentCore();

            // Add a new section.
            Section s = new Section(dc);
            dc.Sections.Add(s);

            // 1. Picture with InlineLayout:

            // Create a new paragraph with picture.
            Paragraph par = new Paragraph(dc);
            s.Blocks.Add(par);
            par.ParagraphFormat.Alignment = HorizontalAlignment.Left;

            // Add some text content.
            par.Content.End.Insert("Shrek and Donkey ", new CharacterFormat() { FontName = "Calibri", Size = 16.0, FontColor = Color.Black });

            // Our picture has InlineLayout - it doesn't have positioning by coordinates
            // and located as flowing content together with text (Run and other Inline elements).
            Picture pict1 = new Picture(dc, InlineLayout.Inline(new Size(100, 100)), pictPath);

            // Add picture to the paragraph.
            par.Inlines.Add(pict1);

            // Add some text content.
            par.Content.End.Insert(" arrive at Farquaad's palace in Duloc, where they end up in a tournament.", new CharacterFormat() { FontName = "Calibri", Size = 16.0, FontColor = Color.Black });

            // 2. Picture with FloatingLayout:
            // Floating layout means that the Picture (or Shape) is positioned by coordinates.
            Picture pict2 = new Picture(dc, pictPath);
            pict2.Layout = FloatingLayout.Floating(
                new HorizontalPosition(50, LengthUnit.Millimeter, HorizontalPositionAnchor.Page),
                new VerticalPosition(70, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                new Size(LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point),
                         LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point))
                         );

            // Set the wrapping style.
            (pict2.Layout as FloatingLayout).WrappingStyle = WrappingStyle.Square;

            // Add our picture into the section.
            s.Content.End.Insert(pict2.Content);

            // Save our document into DOCX format.
            dc.Save(documentPath, new DocxSaveOptions());

            // Open the result for demonstation purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
        }
    }
}
How to add Pictures into a document in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing

Module Sample
    Sub Main()
        AddPictures()
    End Sub

    ''' <summary>
    ''' How to add pictures into a document. 
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/add-pictures.php
    ''' </remarks>
    Sub AddPictures()
        Dim documentPath As String = "Pictures.docx"
        Dim pictPath As String = "..\image1.jpg"

        ' Let's create a simple document.
        Dim dc As New DocumentCore()

        ' Add a new section.
        Dim s As New Section(dc)
        dc.Sections.Add(s)

        ' 1. Picture with InlineLayout:

        ' Create a new paragraph with picture.
        Dim par As New Paragraph(dc)
        s.Blocks.Add(par)
        par.ParagraphFormat.Alignment = HorizontalAlignment.Left

        ' Add some text content.
        par.Content.End.Insert("Shrek and Donkey ", New CharacterFormat() With {
            .FontName = "Calibri",
            .Size = 16.0,
            .FontColor = Color.Black
        })

        ' Our picture has InlineLayout - it doesn't have positioning by coordinates
        ' and located as flowing content together with text (Run and other Inline elements).
        Dim pict1 As New Picture(dc, InlineLayout.Inline(New Size(100, 100)), pictPath)

        ' Add picture to the paragraph.
        par.Inlines.Add(pict1)

        ' Add some text content.
        par.Content.End.Insert(" arrive at Farquaad's palace in Duloc, where they end up in a tournament.", New CharacterFormat() With {
            .FontName = "Calibri",
            .Size = 16.0,
            .FontColor = Color.Black
        })

        ' 2. Picture with FloatingLayout:
        ' Floating layout means that the Picture (or Shape) is positioned by coordinates.
        Dim pict2 As New Picture(dc, pictPath)
        pict2.Layout = FloatingLayout.Floating(New HorizontalPosition(50, LengthUnit.Millimeter, HorizontalPositionAnchor.Page), New VerticalPosition(70, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), New Size(LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point), LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point)))

        ' Set the wrapping style.
        TryCast(pict2.Layout, FloatingLayout).WrappingStyle = WrappingStyle.Square

        ' Add our picture into the section.
        s.Content.End.Insert(pict2.Content)

        ' Save our document into DOCX format.
        dc.Save(documentPath, New DocxSaveOptions())

        ' Open the result for demonstation purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
    End Sub
End Module
See Also