public class Pen extends TransparencySupporter
Defines an object used to draw lines, curves and figures.
This example shows the creation and usage Pen objects. The example creates a new Image and draw Rectangles on Image surface.
// Create an instance of BmpOptions and set its various properties com.aspose.imaging.imageoptions.BmpOptions bmpOptions = new com.aspose.imaging.imageoptions.BmpOptions(); bmpOptions.setBitsPerPixel(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.setSource(new com.aspose.imaging.sources.FileCreateSource("C:\\temp\\sample.bmp", false)); // Create an instance of Image at specified Path com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpOptions, 500, 500); try { // Create an instance of Graphics and initialize it with Image object com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image); // Clear the Graphics sutface with White Color graphics.clear(com.aspose.imaging.Color.getWhite()); // Create an instance of Pen with color Red and width 5 com.aspose.imaging.Pen pen = new com.aspose.imaging.Pen(com.aspose.imaging.Color.getRed(), 5); // Create an instance of HatchBrush and set its properties com.aspose.imaging.brushes.HatchBrush brush = new com.aspose.imaging.brushes.HatchBrush(); brush.setBackgroundColor(com.aspose.imaging.Color.getWheat()); brush.setForegroundColor(com.aspose.imaging.Color.getRed()); // Create an instance of Pen and initialize it with HatchBrush object and width com.aspose.imaging.Pen brushedpen = new com.aspose.imaging.Pen(brush, 5); // Draw Rectangles by specifying Pen object graphics.drawRectangles(pen, new com.aspose.imaging.Rectangle[] { new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(210, 210), new com.aspose.imaging.Size(100, 100)), new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 110), new com.aspose.imaging.Size(100, 100)), new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 310), new com.aspose.imaging.Size(100, 100)) }); // Draw Rectangles by specifying Pen object graphics.drawRectangles( brushedpen, new com.aspose.imaging.Rectangle[] { new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 110), new com.aspose.imaging.Size(100, 100)), new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 310), new com.aspose.imaging.Size(100, 100)) }); // Save all changes. image.save(); } finally { image.dispose(); }
Constructor and Description |
---|
Pen(Brush brush)
Initializes a new instance of the
Pen class with the specified Brush . |
Pen(Brush brush,
float width)
Initializes a new instance of the
Pen class with the specified Brush and Pen.Width . |
Pen(Color color)
Initializes a new instance of the
Pen class with the specified color. |
Pen(Color color,
float width)
Initializes a new instance of the
Pen class with the specified Color and Pen.Width properties. |
Modifier and Type | Method and Description |
---|---|
int |
getAlignment()
Gets the alignment for this
Pen . |
Brush |
getBrush()
Gets the
Brush that determines attributes of this Pen . |
Color |
getColor()
Gets the color of this
Pen . |
float[] |
getCompoundArray()
Gets an array of values that specifies a compound pen.
|
CustomLineCap |
getCustomEndCap()
Gets a custom cap to use at the end of lines drawn with this
Pen . |
CustomLineCap |
getCustomStartCap()
Gets a custom cap to use at the beginning of lines drawn with this
Pen . |
int |
getDashCap()
Gets the cap style used at the end of the dashes that make up dashed lines drawn with this
Pen . |
float |
getDashOffset()
Gets the distance from the start of a line to the beginning of a dash pattern.
|
float[] |
getDashPattern()
Gets an array of custom dashes and spaces.
|
int |
getDashStyle()
Gets the style used for dashed lines drawn with this
Pen . |
int |
getEndCap()
Gets the cap style used at the end of lines drawn with this
Pen . |
int |
getLineJoin()
Gets the join style for the ends of two consecutive lines drawn with this
Pen . |
float |
getMiterLimit()
Gets the limit of the thickness of the join on a mitered corner.
|
int |
getPenType()
Gets the style of lines drawn with this
Pen . |
int |
getStartCap()
Gets the cap style used at the beginning of lines drawn with this
Pen . |
Matrix |
getTransform()
Gets a copy of the geometric transformation for this
Pen . |
float |
getWidth()
Gets the width of this
Pen , in units of the Graphics object used for drawing. |
void |
multiplyTransform(Matrix matrix)
Multiplies the transformation matrix for this
Pen by the specified Matrix . |
void |
multiplyTransform(Matrix matrix,
int order)
Multiplies the transformation matrix for this
Pen by the specified Matrix in the specified order. |
void |
resetTransform()
Resets the geometric transformation matrix for this
Pen to identity. |
void |
rotateTransform(float angle)
Rotates the local geometric transformation by the specified angle.
|
void |
rotateTransform(float angle,
int order)
Rotates the local geometric transformation by the specified angle in the specified order.
|
void |
scaleTransform(float sx,
float sy)
Scales the local geometric transformation by the specified factors.
|
void |
scaleTransform(float sx,
float sy,
int order)
Scales the local geometric transformation by the specified factors in the specified order.
|
void |
setAlignment(int value)
Sets the alignment for this
Pen . |
void |
setBrush(Brush value)
Sets the
Brush that determines attributes of this Pen . |
void |
setColor(Color value)
Sets the color of this
Pen . |
void |
setCompoundArray(float[] value)
Sets an array of values that specifies a compound pen.
|
void |
setCustomEndCap(CustomLineCap value)
Sets a custom cap to use at the end of lines drawn with this
Pen . |
void |
setCustomStartCap(CustomLineCap value)
Sets a custom cap to use at the beginning of lines drawn with this
Pen . |
void |
setDashCap(int value)
Sets the cap style used at the end of the dashes that make up dashed lines drawn with this
Pen . |
void |
setDashOffset(float value)
Sets the distance from the start of a line to the beginning of a dash pattern.
|
void |
setDashPattern(float[] value)
Sets an array of custom dashes and spaces.
|
void |
setDashStyle(int value)
Sets the style used for dashed lines drawn with this
Pen . |
void |
setEndCap(int value)
Sets the cap style used at the end of lines drawn with this
Pen . |
void |
setLineCap(int startCap,
int endCap,
int dashCap)
Sets the values that determine the style of cap used to end lines drawn by this
Pen . |
void |
setLineJoin(int value)
Sets the join style for the ends of two consecutive lines drawn with this
Pen . |
void |
setMiterLimit(float value)
Sets the limit of the thickness of the join on a mitered corner.
|
void |
setStartCap(int value)
Sets the cap style used at the beginning of lines drawn with this
Pen . |
void |
setTransform(Matrix value)
Sets a copy of the geometric transformation for this
Pen . |
void |
setWidth(float value)
Sets the width of this
Pen , in units of the Graphics object used for drawing. |
void |
translateTransform(float dx,
float dy)
Translates the local geometric transformation by the specified dimensions.
|
void |
translateTransform(float dx,
float dy,
int order)
Translates the local geometric transformation by the specified dimensions in the specified order.
|
getOpacity, setOpacity
public Pen(Color color)
Initializes a new instance of the Pen
class with the specified color.
color
- A Color
structure that indicates the color of this Pen
.public Pen(Color color, float width)
Initializes a new instance of the Pen
class with the specified Color
and Pen.Width
properties.
color
- A Color
structure that indicates the color of this Pen
.width
- A value indicating the width of this Pen
.This example shows the creation and usage Pen objects. The example creates a new Image and draw Rectangles on Image surface.
// Create an instance of BmpOptions and set its various properties com.aspose.imaging.imageoptions.BmpOptions bmpOptions = new com.aspose.imaging.imageoptions.BmpOptions(); bmpOptions.setBitsPerPixel(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.setSource(new com.aspose.imaging.sources.FileCreateSource("C:\\temp\\sample.bmp", false)); // Create an instance of Image at specified Path com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpOptions, 500, 500); try { // Create an instance of Graphics and initialize it with Image object com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image); // Clear the Graphics sutface with White Color graphics.clear(com.aspose.imaging.Color.getWhite()); // Create an instance of Pen with color Red and width 5 com.aspose.imaging.Pen pen = new com.aspose.imaging.Pen(com.aspose.imaging.Color.getRed(), 5); // Create an instance of HatchBrush and set its properties com.aspose.imaging.brushes.HatchBrush brush = new com.aspose.imaging.brushes.HatchBrush(); brush.setBackgroundColor(com.aspose.imaging.Color.getWheat()); brush.setForegroundColor(com.aspose.imaging.Color.getRed()); // Create an instance of Pen and initialize it with HatchBrush object and width com.aspose.imaging.Pen brushedpen = new com.aspose.imaging.Pen(brush, 5); // Draw Rectangles by specifying Pen object graphics.drawRectangles(pen, new com.aspose.imaging.Rectangle[] { new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(210, 210), new com.aspose.imaging.Size(100, 100)), new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 110), new com.aspose.imaging.Size(100, 100)), new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 310), new com.aspose.imaging.Size(100, 100)) }); // Draw Rectangles by specifying Pen object graphics.drawRectangles( brushedpen, new com.aspose.imaging.Rectangle[] { new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 110), new com.aspose.imaging.Size(100, 100)), new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 310), new com.aspose.imaging.Size(100, 100)) }); // Save all changes. image.save(); } finally { image.dispose(); }
public Pen(Brush brush)
Initializes a new instance of the Pen
class with the specified Brush
.
brush
- A Brush
that determines the fill properties of this Pen
.com.aspose.ms.System.ArgumentNullException
- brush
is null.public Pen(Brush brush, float width)
Initializes a new instance of the Pen
class with the specified Brush
and Pen.Width
.
brush
- A Brush
that determines the characteristics of this Pen
.width
- The width of the new Pen
.com.aspose.ms.System.ArgumentNullException
- brush
is null.public float getWidth()
Gets the width of this Pen
, in units of the Graphics object used for drawing.
Pen
.com.aspose.ms.System.ArgumentException
- The Pen.Width
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setWidth(float value)
Sets the width of this Pen
, in units of the Graphics object used for drawing.
value
- The width of this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.Width
property is set on an immutable Pen
, such as those returned by the Pens
class.public int getStartCap()
Gets the cap style used at the beginning of lines drawn with this Pen
.
LineCap
values that represents the cap style used at the beginning of lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.StartCap
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setStartCap(int value)
Sets the cap style used at the beginning of lines drawn with this Pen
.
value
- One of the LineCap
values that represents the cap style used at the beginning of lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.StartCap
property is set on an immutable Pen
, such as those returned by the Pens
class.public int getEndCap()
Gets the cap style used at the end of lines drawn with this Pen
.
LineCap
values that represents the cap style used at the end of lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.EndCap
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setEndCap(int value)
Sets the cap style used at the end of lines drawn with this Pen
.
value
- One of the LineCap
values that represents the cap style used at the end of lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.EndCap
property is set on an immutable Pen
, such as those returned by the Pens
class.public int getDashCap()
Gets the cap style used at the end of the dashes that make up dashed lines drawn with this Pen
.
DashCap
values that represents the cap style used at the beginning and end of the dashes that make up dashed lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.DashCap
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setDashCap(int value)
Sets the cap style used at the end of the dashes that make up dashed lines drawn with this Pen
.
value
- One of the DashCap
values that represents the cap style used at the beginning and end of the dashes that make up dashed lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.DashCap
property is set on an immutable Pen
, such as those returned by the Pens
class.public int getLineJoin()
Gets the join style for the ends of two consecutive lines drawn with this Pen
.
LineJoin
that represents the join style for the ends of two consecutive lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.LineJoin
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setLineJoin(int value)
Sets the join style for the ends of two consecutive lines drawn with this Pen
.
value
- A LineJoin
that represents the join style for the ends of two consecutive lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.LineJoin
property is set on an immutable Pen
, such as those returned by the Pens
class.public CustomLineCap getCustomStartCap()
Gets a custom cap to use at the beginning of lines drawn with this Pen
.
CustomLineCap
that represents the cap used at the beginning of lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.CustomStartCap
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setCustomStartCap(CustomLineCap value)
Sets a custom cap to use at the beginning of lines drawn with this Pen
.
value
- A CustomLineCap
that represents the cap used at the beginning of lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.CustomStartCap
property is set on an immutable Pen
, such as those returned by the Pens
class.public CustomLineCap getCustomEndCap()
Gets a custom cap to use at the end of lines drawn with this Pen
.
CustomLineCap
that represents the cap used at the end of lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.CustomEndCap
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setCustomEndCap(CustomLineCap value)
Sets a custom cap to use at the end of lines drawn with this Pen
.
value
- A CustomLineCap
that represents the cap used at the end of lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.CustomEndCap
property is set on an immutable Pen
, such as those returned by the Pens
class.public float getMiterLimit()
Gets the limit of the thickness of the join on a mitered corner.
com.aspose.ms.System.ArgumentException
- The Pen.MiterLimit
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setMiterLimit(float value)
Sets the limit of the thickness of the join on a mitered corner.
value
- The limit of the thickness of the join on a mitered corner.com.aspose.ms.System.ArgumentException
- The Pen.MiterLimit
property is set on an immutable Pen
, such as those returned by the Pens
class.public int getAlignment()
Gets the alignment for this Pen
.
PenAlignment
that represents the alignment for this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.Alignment
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setAlignment(int value)
Sets the alignment for this Pen
.
value
- A PenAlignment
that represents the alignment for this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.Alignment
property is set on an immutable Pen
, such as those returned by the Pens
class.public Matrix getTransform()
Gets a copy of the geometric transformation for this Pen
.
Matrix
that represents the geometric transformation for this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.Transform
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setTransform(Matrix value)
Sets a copy of the geometric transformation for this Pen
.
value
- A copy of the Matrix
that represents the geometric transformation for this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.Transform
property is set on an immutable Pen
, such as those returned by the Pens
class.public int getPenType()
Gets the style of lines drawn with this Pen
.
PenType
enumeration that specifies the style of lines drawn with this Pen
.public Color getColor()
Gets the color of this Pen
.
Color
structure that represents the color of this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.Color
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setColor(Color value)
Sets the color of this Pen
.
value
- A Color
structure that represents the color of this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.Color
property is set on an immutable Pen
, such as those returned by the Pens
class.public Brush getBrush()
Gets the Brush
that determines attributes of this Pen
.
Brush
that determines attributes of this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.Brush
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setBrush(Brush value)
Sets the Brush
that determines attributes of this Pen
.
value
- A Brush
that determines attributes of this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.Brush
property is set on an immutable Pen
, such as those returned by the Pens
class.public int getDashStyle()
Gets the style used for dashed lines drawn with this Pen
.
DashStyle
that represents the style used for dashed lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.DashStyle
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setDashStyle(int value)
Sets the style used for dashed lines drawn with this Pen
.
value
- A DashStyle
that represents the style used for dashed lines drawn with this Pen
.com.aspose.ms.System.ArgumentException
- The Pen.DashStyle
property is set on an immutable Pen
, such as those returned by the Pens
class.public float getDashOffset()
Gets the distance from the start of a line to the beginning of a dash pattern.
public void setDashOffset(float value)
Sets the distance from the start of a line to the beginning of a dash pattern.
value
- The distance from the start of a line to the beginning of a dash pattern.public float[] getDashPattern()
Gets an array of custom dashes and spaces.
com.aspose.ms.System.ArgumentException
- The Pen.DashPattern
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setDashPattern(float[] value)
Sets an array of custom dashes and spaces.
value
- An array of real numbers that specifies the lengths of alternating dashes and spaces in dashed lines.com.aspose.ms.System.ArgumentException
- The Pen.DashPattern
property is set on an immutable Pen
, such as those returned by the Pens
class.public float[] getCompoundArray()
Gets an array of values that specifies a compound pen. A compound pen draws a compound line made up of parallel lines and spaces.
com.aspose.ms.System.ArgumentException
- The Pen.CompoundArray
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setCompoundArray(float[] value)
Sets an array of values that specifies a compound pen. A compound pen draws a compound line made up of parallel lines and spaces.
value
- An array of real numbers that specifies the compound array. The elements in the array must be in increasing order, not less than 0, and not greater than 1.com.aspose.ms.System.ArgumentException
- The Pen.CompoundArray
property is set on an immutable Pen
, such as those returned by the Pens
class.public void setLineCap(int startCap, int endCap, int dashCap)
Sets the values that determine the style of cap used to end lines drawn by this Pen
.
startCap
- A LineCap
that represents the cap style to use at the beginning of lines drawn with this Pen
.endCap
- A LineCap
that represents the cap style to use at the end of lines drawn with this Pen
.dashCap
- A LineCap
that represents the cap style to use at the beginning or end of dashed lines drawn with this Pen
.public void resetTransform()
Resets the geometric transformation matrix for this Pen
to identity.
public void multiplyTransform(Matrix matrix)
Multiplies the transformation matrix for this Pen
by the specified Matrix
.
matrix
- The Matrix
object by which to multiply the transformation matrix.public void multiplyTransform(Matrix matrix, int order)
Multiplies the transformation matrix for this Pen
by the specified Matrix
in the specified order.
matrix
- The Matrix
by which to multiply the transformation matrix.order
- The order in which to perform the multiplication operation.public void translateTransform(float dx, float dy)
Translates the local geometric transformation by the specified dimensions. This method prepends the translation to the transformation.
dx
- The value of the translation in x.dy
- The value of the translation in y.public void translateTransform(float dx, float dy, int order)
Translates the local geometric transformation by the specified dimensions in the specified order.
dx
- The value of the translation in x.dy
- The value of the translation in y.order
- The order (prepend or append) in which to apply the translation.public void scaleTransform(float sx, float sy)
Scales the local geometric transformation by the specified factors. This method prepends the scaling matrix to the transformation.
sx
- The factor by which to scale the transformation in the x-axis direction.sy
- The factor by which to scale the transformation in the y-axis direction.public void scaleTransform(float sx, float sy, int order)
Scales the local geometric transformation by the specified factors in the specified order.
sx
- The factor by which to scale the transformation in the x-axis direction.sy
- The factor by which to scale the transformation in the y-axis direction.order
- A MatrixOrder
that specifies whether to append or prepend the scaling matrix.public void rotateTransform(float angle)
Rotates the local geometric transformation by the specified angle. This method prepends the rotation to the transformation.
angle
- The angle of rotation.public void rotateTransform(float angle, int order)
Rotates the local geometric transformation by the specified angle in the specified order.
angle
- The angle of rotation.order
- A MatrixOrder
that specifies whether to append or prepend the rotation matrix.