Canvas Object

Overview

The Canvas object encapsulates properties and methods which enable drawing and typing on top of an image. This method is returned by the Canvas property of the main ASPJpeg object.

Member List

Properties


Brush As IAspJpegBrush (Read-only)

Returns the Brush object which enables setting brush properties.

See also: Chapter 5 - Drawing & Typing.


Font As IAspJpegFont (Read-only)

Returns the Font object which enables setting font properties.

See also: Chapter 5 - Drawing & Typing.


ParagraphHeight As Long (Read-only)

Returns the height (in pixels) of a text paragraph just rendered by a call to PrintTextEx. 0 by default. This property was introduced by Version 1.9.

See also: Section 5.3 - Advanced Text Drawing with PrintTextEx.


Pen As IAspJpegPen (Read-only)

Returns the Pen object which enables setting pen properties.

See also: Chapter 5 - Drawing & Typing.

Methods


Sub Arc(X As Long, Y As Long, Radius As Long, StartAngle As Long, ArcAngle As Long)
Same as DrawArc. Obsolete, supported for backwards compatibility only.

Sub Bar(Left As Long, Top As Long, Right As Long, Bottom As Long)
Same as DrawBar. Obsolete, supported for backwards compatibility only.

Sub Circle(X As Long, Y As Long, Radius As Long)
Same as DrawCircle. Obsolete, supported for backwards compatibility only.

Sub ClearPath()

Clears the current path. A new path is to be populated via the methods MoveTo and LineTo. A path can be rendered using the methods DrawPolyEx and FillPolyEx.

This method was introduced in Version 2.1.

See also: Section 5.4 - Anti-aliased Drawing Routines.


Sub DrawArc(X As Long, Y As Long, Radius As Long, StartAngle As Long, ArcAngle As Long)

Draws a circular arc with a center in (X, Y). The arc radius is specified by Radius (in pixels). StartAngle specifies the angle (in degrees) of the arc's starting point, and ArcAngle specifies the arc's span, in the counterclockwise direction. Uses the current pen. Arcs are not filled.

See also: Chapter 5 - Drawing & Typing.


Sub DrawBar(Left As Long, Top As Long, Right As Long, Bottom As Long)

Draws a rectangle specified by the coordinates of its upper-left and lower-right corners (in pixels) using the current pen and brush.

See also: Chapter 5 - Drawing & Typing.


Sub DrawCircle(X As Long, Y As Long, Radius As Long)

Draws a circle specified by its center coordinates and radius (in pixels) using the current pen and brush.

See also: Chapter 5 - Drawing & Typing.


Sub DrawEllipse(Left As Long, Top As Long, Right As Long, Bottom As Long)

Draws an ellipse specified by the coordinates of its bounding rectangle (in pixels) using the current pen and brush.

See also: Chapter 5 - Drawing & Typing.


Sub DrawImage(X As Long, Y As Long, Picture As ASPJpeg, Optional Opacity = 1, Optional TranspColor, Optional TranspDeviation = 0)

Draws an image on top of the current image. X and Y are coordinates (in pixels) of the upper-left corner of Picture within the current image. Picture is another instance of the AspJpeg object.

As of Version 2.5, if a 4-point path is defined prior to calling this method (a call to MoveTo followed by 3 calls to LineTo,) this method applies perspective projection to Picture, and all arguments except Picture and Opacity are ignored.

Opacity is a number between 0 and 1 which specifies the degree of opacity when Picture is blended onto the current image. Default value: 1 (opaque).

TranspColor specifies the color of pixels within Picture to be made transparent when blending the picture onto the current image. This must be an HTML-style hexadecimal number, e.g. &HFF0000 (red). By default, no pixels will be made transparent.

TranspDeviation is a number between 0 and 255 which specifies an allowable deviation of the RGB color values from TranspColor. Default value: 0. If TranspColor is not specified, this argument is ignored.

Starting with Version 1.9, this method requires that the color component count of the source and destination images match. E.g. an RGB image cannot be drawn on top of a CMYK one, or vice versa.

See also: Section 6.1 - Image Drawing, Section 6.4 - Perspective Projection.


Sub DrawImageChromaKey(X As Long, Y As Long, Picture As ASPJpeg, R As Long, G As Long, B As Long, Dist1 As Long, Dist2 As Long)

Draws Picture on the current image, removes the monochromatic background of the image being drawn by making it transparent to achieve the "chroma key" effect.

X and Y are coordinates (in pixels) of the upper-left corner of Picture within the current image.

Picture is another instance of the AspJpeg object representing the image with a monochromatic background, usually green or blue.

R, G, B are the RGB values (in the range [0, 255]) of the key color of the background.

Dist1, Dist2 are color distances controlling the range of colors to be made transparent. Chosen by trial and error. The values (20, 80) usually produce good results.

This method was introduced in Version 2.6.

See also: Section 8.7 - Chroma Key.


Sub DrawImageUV(Image As ASPJpeg)

Draws Image mapped to a 3D surface on the current image. The 3D surface equations as well as various other parameters pertaining to the 3D surface mapping process are specified via the Canvas.UV object.

This method was introduced in Version 2.8.

See also: Chapter 11 - 3D Surface Mapping.


Sub DrawLine(x1 As Long, y1 As Long, x2 As Long, y2 As Long)

Draws a line specified by the coordinates of its starting and ending points (in pixels) using the current pen's width and color.

See also: Chapter 5 - Drawing & Typing.


Sub DrawLineEx(x1 As Long, y1 As Long, x2 As Long, y2 As Long)

Draws an anti-aliased line specified by the coordinates of its starting and ending points (in pixels) using the current pen's width, color and opacity.

This method was introduced in Version 2.1.

See also: Section 5.4 - Anti-aliased Drawing Routines.


Sub DrawPie(X As Long, Y As Long, Radius As Long, StartAngle As Long, EndAngle As Long)

Draws a pie-shaped wedge with a center in (X, Y). The radius is specified by Radius (in pixels). StartAngle specifies the angle (in degrees) of the arc's starting point, and EndAngle specifies the arc's ending point, in the counterclockwise direction. Uses the current pen and brush. This method was introduced by version 2.0.

See also: Chapter 5 - Drawing & Typing.


Sub DrawPNG(X As Long, Y As Long, Path As String)

Draws a PNG, GIF or WEBP picture specified by Path on top of a larger image and takes into account the picture's alpha channel, if present, for better blending with the background. X and Y specify the horizontal and vertical offsets of the picture being drawn relative to the larger image. This method was introduced by version 1.7.

Starting with Version 1.8, DrawPNG also recognizes GIF format and should be used instead of the DrawImage method to render GIF images with transparency correctly. Version 2.9.0.2+ is required for WEBP support.

Starting with Version 2.7.0.3, the method takes into account both the alpha channel of the background image and the alpha channel of the image being drawn for more accurate blending.

See also: Section 6.3 - PNG & WEBP Alpha Channel.


Sub DrawPNGBinary(X As Long, Y As Long, Image As Variant)

Same as DrawPNG except the Image being drawn is specified as a binary array of bytes as opposed to a file path. This method was introduced by version 1.7.

See also: Section 6.3 - PNG & WEBP Alpha Channel.


Sub DrawPolyEx(ID As String, Value As String)

Draws an anti-aliased polygon (broken line) through the points of the current path using the current pen's width, color and opacity. The path is built using the methods MoveTo and LineTo.

This method was introduced in Version 2.1.

See also: Section 5.4 - Anti-aliased Drawing Routines.


Sub DrawQuad(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long,X3 As Long, Y3 As Long, X4 As Long, Y4 As Long)

Draws a quadrilateral specified by the coordinates of its 4 corners using the current pen and brush. This method was introduced by version 2.0.

See also: Chapter 5 - Drawing & Typing.


Sub DrawRoundRect(Left As Long, Top As Long, Right As Long, Bottom As Long, CornerWidth As Long, CornerHeight As Long)

Draws a rectangle with rounded corners using the current pen and brush. The rectangle is specified by the coordinates of its upper-left and lower-right corners (in pixels). The corners are rounded by an ellipse with the width and height specified by CornerWidth andCornerHeight. This method was introduced by version 2.0.

See also: Chapter 5 - Drawing & Typing.


Sub Ellipse(Left As Long, Top As Long, Right As Long, Bottom As Long)
Same as DrawEllipse. Obsolete, supported for backwards compatibility only.

Sub FillEllipseEx(X As Long, Y As Long, Radius1 As Long, Radius2 As Long, StartAngle As Long, EndAngle As Long)

Fills an anti-aliased ellipse (or circle) or a sector thereof. X and Y specify the coordinates of the center. Radius1 and Radius2 specify the ellipse radii. If the two values are the same, a regular circle is drawn. StartAngle and EndAngle specify the angles (in degrees) of the start and end of the sector, if applicable. If the two values are 0, a full ellipse (circle) is drawn.

This method was introduced in Version 2.1.

See also: Section 5.4 - Anti-aliased Drawing Routines.


Sub FillPolyEx(ID As String, Value As String)

Fills an anti-aliased polygon specified by the current path using the current brush's color and opacity. The path is built using the methods MoveTo and LineTo.

This method was introduced in Version 2.1.

See also: Section 5.4 - Anti-aliased Drawing Routines.


Function GetTextExtent(TextString As String, Optional Language = 1) As Long

Computes and returns the horizontal extent, in pixels, of the specified text string if rendered using the current font family, width and size. This method is useful for displaying centered text.

Note that the method PrintTextEx has built-in support for text alignment.

See also: Section 6.1 - Image Drawing.


Sub Line(x1 As Long, y1 As Long, x2 As Long, y2 As Long)
Same as DrawLine. Obsolete, supported for backwards compatibility only.

Sub LineTo(x As Long, y As Long)

Adds a new point with the coordinates (x, y) to the current path. A path can be rendered using the methods DrawPolyEx and FillPolyEx. As of Version 2.5, a path also affects the DrawImage method.

This method was introduced in Version 2.1.

See also: Section 5.4 - Anti-aliased Drawing Routines, Section 6.4 - Perspective Projection.


Sub MoveTo(x As Long, y As Long)

Clears the current path, creates a new path, and adds a first point with the coordinates (x, y) to the new path. A path can be rendered using the methods DrawPolyEx and FillPolyEx. As of Version 2.5, a path also affects the DrawImage method.

This method was introduced in Version 2.1.

See also: Section 5.4 - Anti-aliased Drawing Routines, Section 6.4 - Perspective Projection.


Sub Print(X As Long, Y As Long, TextString As String, Optional Language = 1)

Prints TextString starting at (X, Y) using the current font.

Language is an optional parameter which should be used when TextString is in a language other than US ASCII. Valid values are:

0 (ANSI_CHARSET)
1 (DEFAULT_CHARSET)
2 (SYMBOL_CHARSET) 2
128 (SHIFTJIS_CHARSET)
129 (HANGEUL_CHARSET)
134 (GB2312_CHARSET)
136 (CHINESEBIG5_CHARSET)
255 (OEM_CHARSET)
130 (JOHAB_CHARSET)
177 (HEBREW_CHARSET)
178 (ARABIC_CHARSET)
161 (GREEK_CHARSET)
162 (TURKISH_CHARSET)
163 (VIETNAMESE_CHARSET)
222 (THAI_CHARSET)
238 (EASTEUROPE_CHARSET)
204 (RUSSIAN_CHARSET)
77 (MAC_CHARSET)
186 (BALTIC_CHARSET)

See also: Chapter 5 - Drawing & Typing.

Note: AspJpeg 1.8+ provides a more versatile PrintTextEx method described below.


Sub PrintText(X As Long, Y As Long, TextString As String, Optional Language = 1)
Same as Print. Added in AspJpeg 2.1.0.1 for compatibility with VB, as the name Print is a reserved word in VB and causes compile-time errors.

Function PrintTextEx(Text As String, X As Long, Y As Long, FontPath As String) As Long

Prints anti-aliased text using a TrueType/OpenType or Type 1 font specified by its physical path. Supports word wrapping, rotation, text alignment (to the left, right, center and justified) and adjustable line spacing. This method was introduced in Version 1.8 as a more versatile alternative to the PrintText method.

Text - specifies the text string to be printed (in Unicode format). May contain CR/LF characters for multi-line display.

X, Y - coordinates of the lower-left corner of the first character of the first line, relative to the upper-left corner of the image.

FontPath - specifies a physical path to the font file. The font does not need to be properly registered on the system as long as the path to the font file is known.

Additional optional parameters are specified via the Font object. The following Font properties affect PrintTextEx:

Font.Color - specifies the current text color as a Hex value. E.g. &HFF0000FF is blue.

Font.Rotation - specifies the rotation angle around the (X, Y) point in degrees. A positive value creates a counter-clockwise rotation.

Font.Size - specifies font size in pixels.

Font.Spacing - specifies an adjustment in pixels for the default line spacing when multi-line text is being rendered. A positive value increases the line spacing, a negative one decreases it.

Font.Width - specifies the width of an area in which the text string is to be inscribed. Word wrapping occurs if the text string does not fit in the area. This property must also be set if non-default text alignment is specified via Font.Align.

Font.Align - specifies text alignment. Valid values are: 0 - left (default), 1 - right, 2 - center, and 3 - justified. For values other than 0, Font.Width must also be specified.

Font.Opacity - specifies text opacity. Valid values are in the range [0, 1] with 0 meaning full transparency and 1 full opacity.

Font.Underline - (Version 2.1+) specifies if the text should be underlined if set to True. The color and width of the underline should be specified separately via Pen.Color and Pen.Width, respectively.

Returns the width (in pixels) of the text string being drawn. If the string is split into multiple lines, returns the width of the longest line. Starting with version 1.9, the height of the text paragraph just rendered can be obtained via the property ParagraphHeight.

For more information, see Section 5.3 - Advanced Text Drawing with PrintTextEx.