Pen Class
Defines an object used to draw lines, curves and figures.
Inheritance Hierarchy

Namespace: Aspose.Imaging
Assembly: Aspose.Imaging (in Aspose.Imaging.dll) Version: 19.9
Syntax
[SerializableAttribute]
public class Pen : TransparencySupporter

The Pen type exposes the following members.

Constructors
  NameDescription
Public methodPen(Brush)
Initializes a new instance of the Pen class with the specified Brush.
Public methodPen(Color)
Initializes a new instance of the Pen class with the specified color.
Public methodPen(Brush, Single)
Initializes a new instance of the Pen class with the specified Brush and Width.
Public methodCode examplePen(Color, Single)
Initializes a new instance of the Pen class with the specified Color and Width properties.
Properties
  NameDescription
Public propertyAlignment
Gets or sets the alignment for this Pen.
Public propertyBrush
Gets or sets the Brush that determines attributes of this Pen.
Public propertyColor
Gets or sets the color of this Pen.
Public propertyCompoundArray
Gets or sets an array of values that specifies a compound pen. A compound pen draws a compound line made up of parallel lines and spaces.
Public propertyCustomEndCap
Gets or sets a custom cap to use at the end of lines drawn with this Pen.
Public propertyCustomStartCap
Gets or sets a custom cap to use at the beginning of lines drawn with this Pen.
Public propertyDashCap
Gets or sets the cap style used at the end of the dashes that make up dashed lines drawn with this Pen.
Public propertyDashOffset
Gets or sets the distance from the start of a line to the beginning of a dash pattern.
Public propertyDashPattern
Gets or sets an array of custom dashes and spaces.
Public propertyDashStyle
Gets or sets the style used for dashed lines drawn with this Pen.
Public propertyEndCap
Gets or sets the cap style used at the end of lines drawn with this Pen.
Public propertyLineJoin
Gets or sets the join style for the ends of two consecutive lines drawn with this Pen.
Public propertyMiterLimit
Gets or sets the limit of the thickness of the join on a mitered corner.
Public propertyOpacity
Gets or sets the object's opacity. The value should be between 0 and 1. Value of 0 means that object is fully visible, value of 1 means the object is fully opaque.
(Inherited from TransparencySupporter.)
Public propertyPenType
Gets the style of lines drawn with this Pen.
Public propertyStartCap
Gets or sets the cap style used at the beginning of lines drawn with this Pen.
Public propertyTransform
Gets or sets a copy of the geometric transformation for this Pen.
Public propertyWidth
Gets or sets the width of this Pen, in units of the Graphics object used for drawing.
Methods
  NameDescription
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodMultiplyTransform(Matrix)
Multiplies the transformation matrix for this Pen by the specified Matrix.
Public methodMultiplyTransform(Matrix, MatrixOrder)
Multiplies the transformation matrix for this Pen by the specified Matrix in the specified order.
Public methodResetTransform
Resets the geometric transformation matrix for this Pen to identity.
Public methodRotateTransform(Single)
Rotates the local geometric transformation by the specified angle. This method prepends the rotation to the transformation.
Public methodRotateTransform(Single, MatrixOrder)
Rotates the local geometric transformation by the specified angle in the specified order.
Public methodScaleTransform(Single, Single)
Scales the local geometric transformation by the specified factors. This method prepends the scaling matrix to the transformation.
Public methodScaleTransform(Single, Single, MatrixOrder)
Scales the local geometric transformation by the specified factors in the specified order.
Public methodSetLineCap
Sets the values that determine the style of cap used to end lines drawn by this Pen.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTranslateTransform(Single, Single)
Translates the local geometric transformation by the specified dimensions. This method prepends the translation to the transformation.
Public methodTranslateTransform(Single, Single, MatrixOrder)
Translates the local geometric transformation by the specified dimensions in the specified order.
Examples
This example shows the creation and usage Pen objects. The example creates a new Image and draw Rectangles on Image surface.
[C#]

//Create an instance of BmpOptions and set its various properties
Aspose.Imaging.ImageOptions.BmpOptions bmpOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
bmpOptions.BitsPerPixel = 24;

//Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
//Second Boolean parameter determines if the file to be created IsTemporal or not
bmpOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"C:\temp\sample.bmp", false);

//Create an instance of Image at specified Path
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(bmpOptions, 500, 500))
{
    //Create an instance of Graphics and initialize it with Image object
    Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);

    //Clear the Graphics sutface with White Color
    graphics.Clear(Aspose.Imaging.Color.White);

    //Create an instance of Pen with color Red and width 5
    Aspose.Imaging.Pen pen = new Aspose.Imaging.Pen(Aspose.Imaging.Color.Red, 5f);

    //Create an instance of HatchBrush and set its properties
    Aspose.Imaging.Brushes.HatchBrush brush = new Aspose.Imaging.Brushes.HatchBrush();
    brush.BackgroundColor = Aspose.Imaging.Color.Wheat;
    brush.ForegroundColor = Aspose.Imaging.Color.Red;

    //Create an instance of Pen
    //initialize it with HatchBrush object and width
    Aspose.Imaging.Pen brusedpen = new Pen(brush, 5);

    //Draw Rectangles by specifying Pen object
    graphics.DrawRectangles(pen, new[]
    {
        new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(210, 210), new Aspose.Imaging.Size(100, 100)),
        new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(110, 110), new Aspose.Imaging.Size(100, 100)),
        new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(310, 310), new Aspose.Imaging.Size(100, 100))
    });

    //Draw Rectangles by specifying Pen object
    graphics.DrawRectangles(brusedpen, new[]
    {
        new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(310, 110), new Aspose.Imaging.Size(100, 100)),
        new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(110, 310), new Aspose.Imaging.Size(100, 100))
    });

    // save all changes.
    image.Save();
}
See Also