• References
    • Main
    • RenderKit
    • LibJS
    • Canvas
  • Components
    • Overview
    • Page
    • Basic
      • Rectangle
      • Text
      • Button
      • HTML Article
      • Toggle Button
      • Tiler
      • Web View
      • Image Zoomer
    • Navigation
      • Carousel
    • Forms
      • Form
      • Text Entry
    • Layout
      • Group
  • Web API
  • Tutorials
  • Contact
Menu
  • References
    • Main
    • RenderKit
    • LibJS
    • Canvas
  • Components
    • Overview
    • Page
    • Basic
      • Rectangle
      • Text
      • Button
      • HTML Article
      • Toggle Button
      • Tiler
      • Web View
      • Image Zoomer
    • Navigation
      • Carousel
    • Forms
      • Form
      • Text Entry
    • Layout
      • Group
  • Web API
  • Tutorials
  • Contact
  • Canvas_Overview
  • canvasAdaptiveThreshold
  • canvasAddBezier3
  • canvasAddBezier4
  • canvasAddEllipse
  • canvasAddLine
  • canvasAddMove
  • canvasAddRoundedRect
  • canvasAddWedge
  • canvasAutoBrightnessContrast
  • canvasAutoColor
  • canvasBeginPath
  • canvasBoxBlur
  • canvasBoxBlurRegion
  • canvasCalcPsnr
  • canvasCalculateTextWidth
  • canvasChromaKey
  • canvasClosePath
  • canvasCopyBuffer
  • canvasCreateNew
  • canvasCrop
  • canvasDashAdd
  • canvasDashClear
  • canvasDetectBlobs
  • canvasDetectSegments
  • canvasDetectSlidingTemplate
  • canvasDrawPathFill
  • canvasDrawPathStroke
  • canvasDrawTextFill
  • canvasDrawTextStroke
  • canvasFlipHorizontal
  • canvasFlipVertical
  • canvasGetHeight
  • canvasGetPixel
  • canvasGetPixelData
  • canvasGetWidth
  • canvasGradientAddPoint
  • canvasGradientClear
  • canvasHsv
  • canvasInvert
  • canvasLighting
  • canvasPrepareSvg
  • canvasReadAprilTags
  • canvasReadBarcode
  • canvasReadQrcode
  • canvasResetColor
  • canvasResetTransform
  • canvasResize
  • canvasRotate
  • canvasRotateTransform
  • canvasSaveAs
  • canvasScaleTransform
  • canvasSetBrushAngle
  • canvasSetBrushBlendMode
  • canvasSetBrushColor
  • canvasSetBrushGradientEnd
  • canvasSetBrushGradientStart
  • canvasSetBrushMode
  • canvasSetBrushPointSample
  • canvasSetBrushPosition
  • canvasSetBrushScale
  • canvasSetBrushSource
  • canvasSetBrushSourceBottomRight
  • canvasSetBrushSourceTopLeft
  • canvasSetFontFilename
  • canvasSetFontHeight
  • canvasSetPixel
  • canvasSetPixelData
  • canvasSetStrokeCap
  • canvasSetStrokeInnerJoin
  • canvasSetStrokeInnerMiterLimit
  • canvasSetStrokeJoin
  • canvasSetStrokeMiterLimit
  • canvasSetStrokeWidth
  • canvasSkewTransform
  • canvasSmoothPath
  • canvasStampAdaptiveThreshold
  • canvasStampAutoBrightnessContrast
  • canvasStampAutoColor
  • canvasStampAvgDelta
  • canvasStampBarcode
  • canvasStampBuffer
  • canvasStampChromaKey
  • canvasStampColorChannel
  • canvasStampCustom
  • canvasStampHsv
  • canvasStampImage
  • canvasStampImageCenter
  • canvasStampImagePerspective
  • canvasStampImageWarp
  • canvasStampKernel
  • canvasStampLighting
  • canvasStampMinmaxBlend
  • canvasStampMorphological
  • canvasStampQr
  • canvasStampSvg
  • canvasToTexture
  • canvasTranslateTransform

Global

Members


Canvas_Overview

Canvas overview

Canvas is a sophisticated palette of drawing and analysis capabilities to let you
both construct 2D images using vector and bitmap graphics but also to use
image processing to retrieve information.
Canvas is an RGBA pixel buffer you can load images, draw shapes, perform
per pixel and per kernel operations. This can be a buffer you create or one supplied
as part of a video stream or from an external library.

To use a canvas component, start by adding one to a page. Then you need to set its properties in the Editor.
the Canvas Component can be passed as a parameter to JavaScript actions. Code within an action can set properties and call methods on the Canvas Component.
You can choose to either have an image as your background or generate a color for the background and this will set the size of your Canvas Component.
The size of your canvas will either be the size of the image selected or the width/height properties depending on the options you choose.
In either case the size of the canvas background can affect later functions applied to your Canvas Component.
In the below example the size and position of the square can be affected by the size of the Canvas Component.
If your image or generated background has a width of 50 pixels but your Canvas Component has a width of 200 pixels then the canvas space and background is up-scaled to match.
A background of 50 pixels in a Canvas Component taking up 200 pixels on screen would mean the canvas space is being up-scaled by a factor of x4.
This means that all the values of the square you draw will be magnified by a scale of x4 as well. This will make your square appear 4 times as large.
The starting X position for drawing is also magnified. A value of 100 would end up as 400. This would appear well passed the end of the 200 width Canvas Component and may not be able to be seen.
In the other direction if you choose a very large image or set the generated size very large then your square will appear very small as everything is down-scaled.
For these reasons it is recommended when following the example code in this help document that you use canvas size of about 500x500 pixels.
The "stretch" resize property option can also affect the display of the square. If the canvas is stretched the square will strecth also and become a rectangle.
For other components you often want to deal with the width and height of the component. However most of the functions here don't care about the component size, they
only care about the canvas size which can be gotten from the properties pixelWidth and pixelHeight.

canvasCreateNew canvasCreateNew
canvasGetWidth canvasGetWidth
canvasGetHeight canvasGetHeight

Coordinates

All coordinates are (0,0) in the top left of the buffer. X increases to the
right and Y increases down the image towards the bottom. All angles are in
degrees clockwise.

Drawing

Drawing on an image_buffer has multiple styles. Vector and image processing.

Vector commands are built into a list of paths controlled with these methods:

canvasBeginPath canvasBeginPath
canvasClosePath canvasClosePath
canvasSmoothPath canvasSmoothPath turns lines into curves

Drawing commands are then added to the path using the following Add methods:

canvasAddMove canvasAddMove
canvasAddLine canvasAddLine
canvasAddBezier3 canvasAddBezier3
canvasAddBezier4 canvasAddBezier4
canvasAddEllipse canvasAddEllipse
canvasAddRoundedRect canvasAddRoundedRect
canvasAddWedge canvasAddWedge

Paths can be manipulated with the following transforms:

canvasResetTransform canvasResetTransform
canvasRotateTransform canvasRotateTransform
canvasSkewTransform canvasSkewTransform
canvasScaleTransform canvasScaleTransform
canvasTranslateTransform canvasTranslateTransform

The drawing commands are then rasterized using:

canvasDrawPathStroke canvasDrawPathStroke
canvasDrawPathFill canvasDrawPathFill

Brushes determine how strokes and fills are drawn. These commands update the brush:

canvasSetBrushMode canvasSetBrushMode
canvasSetBrushBlendMode canvasSetBrushBlendMode
canvasSetBrushColor canvasSetBrushColor
canvasSetBrushSource canvasSetBrushSource
canvasSetBrushPointSample canvasSetBrushPointSample
canvasSetBrushPosition canvasSetBrushPosition
canvasSetBrushAngle canvasSetBrushAngle
canvasSetBrushScale canvasSetBrushScale
canvasSetBrushSourceTopLeft canvasSetBrushSourceTopLeft
canvasSetBrushSourceBottomRight canvasSetBrushSourceBottomRight
canvasSetStrokeWidth canvasSetStrokeWidth
canvasSetStrokeCap canvasSetStrokeCap
canvasSetStrokeJoin canvasSetStrokeJoin
canvasSetStrokeInnerJoin canvasSetStrokeInnerJoin
canvasSetStrokeInnerMiterLimit canvasSetStrokeInnerMiterLimit
canvasSetStrokeMiterLimit canvasSetStrokeMiterLimit

Brushes can have gradients as follows:

canvasSetBrushGradientStart canvasSetBrushGradientStart
canvasSetBrushGradientEnd canvasSetBrushGradientEnd
canvasGradientClear canvasGradientClear
canvasGradientAddPoint canvasGradientAddPoint adds multi point gradients to the start and end

Strokes can have dashes added as follows:

canvasDashClear canvasDashClear
canvasDashAdd canvasDashAdd

Text makes it's own paths on the fly using:

canvasSetfontFilename canvasSetfontFilename
canvasSetfontHeight canvasSetfontHeight
canvasCalculateTextWidth canvasCalculateTextWidth
canvasDrawTextStroke canvasDrawTextStroke
canvasDrawTextFill canvasDrawTextFill

Full Canvas Operations

canvasCopyBuffer canvasCopyBuffer
canvasInvert canvasInvert
canvasRotate canvasRotate
canvasCrop canvasCrop
canvasResize canvasResize
canvasCalcPsnr canvasCalcPsnr
canvasFlipVertical canvasFlipVertical
canvasFlipHorizontal canvasFlipHorizontal
canvasAutoBrightnessContrast canvasAutoBrightnessContrast
canvasAutoColor canvasAutoColor
canvasChromaKey canvasChromaKey
canvasLighting canvasLighting
canvasHsv canvasHsv
canvasAdaptiveThreshold canvasAdaptiveThreshold
canvasBoxBlur canvasBoxBlur
canvasBoxBlurRegion canvasStampBoxBlur

Bitmap Operations

canvasStampBuffer canvasStampBuffer
canvasStampColorChannel canvasStampColorChannel
canvasStampLighting canvasStampLighting
canvasStampKernel canvasStampKernel
canvasStampMorphological canvasStampMorphological
canvasStampAdaptiveThreshold canvasStampAdaptiveThreshold
canvasStampHsv canvasStampHsv
canvasStampAutoColor canvasStampAutoColor
canvasStampAutoBrightnessContrast canvasStampAutoBrightnessContrast
canvasStampChromaKey canvasStampChromaKey
canvasStampMinmaxBlend canvasStampMinmaxBlend
canvasStampAvgDelta canvasStampAvgDelta
canvasStampCustom canvasStampCustom
canvasStampImage canvasStampImage
canvasStampImageCenter canvasStampImageCenter
canvasStampImageWarp canvasStampImageWarp
canvasStampImagePerspective canvasStampImagePerspective
canvasStampSvg canvasStampSvg
canvasPrepareSvg canvasPrepareSvg
canvasStampBarcode canvasStampBarcode
canvasStampQr canvasStampQr

Detectors

canvasReadQrcode canvasReadQrcode
canvasReadBarcode canvasReadBarcode
canvasReadAprilTags canvasReadAprilTags
canvasDetectSlidingTemplate canvasDetectSlidingTemplate
canvasDetectBlobs canvasDetectBlobs
canvasDetectSegments canvasDetectSegments

I/O functions

canvasGetPixel canvasGetPixel
canvasSetPixel canvasSetPixel
canvasSaveAs canvasSaveAs
canvasToTexture canvasToTexture

Methods


canvasAdaptiveThreshold(canvas, strength, radius, blend)

canvasAdaptiveThreshold thresholds with variable strength given a radius of local contrast. The blend 0-1 is how much of the image is preserved vs thresholded.
This applies a 0-1 threshold with an adaptive radius in pixels. The blend 0-1 is how much of the image is preserved vs thresholded.
Parameters:
Name Type Description
canvas

component

the target canvas
strength

real

-1 to 1 how strong the threshold is towards binary
radius

int

1 to 1000 how wide the radius to check for local contrast
blend

real

0 to 1 how much of the image is preserved vs thresholded (0.5 is a common value)
Example
  1. registerAction('canvasAdaptiveThresholdTest', '', 'canvasAdaptiveThresholdTest', 'component:Canvas:canvas');
  2. function canvasAdaptiveThresholdTest(canvas) {
  3. canvasAdaptiveThreshold(canvas, 0.2, 10, 0.5);
  4. }

canvasAddBezier3(canvas, x1,y1, x2,y2, x3,y3)

canvasAddBezier3 Adds a parabolic Bezier curve (one control point) to the current path
Parameters:
Name Type Description
canvas

component

the target canvas.
x1,y1

real

start point.
x2,y2

real

control point.
x3,y3

real

end point.
Example
  1. registerAction('canvasAddBezier3Test', '', 'canvasAddBezier3Test', 'component:Canvas:canvas');
  2. function canvasAddBezier3Test(canvas) {
  3. setProperty(canvas, 'stroke_style', '#FF0000FF');
  4. setProperty(canvas, 'line_width', 4);
  5. canvasBeginPath(canvas);
  6. canvasAddMove(canvas, 150, 150);
  7. canvasAddBezier3(canvas, 150, 150, 175, 200, 150, 250);
  8. canvasDrawPathStroke(canvas);
  9. }

canvasAddBezier4(canvas, x1,y1, x2,y2, x3,y3, x4,y4)

canvasAddBezier4 Adds a cubic Bezier curve (two control points) to the current path.
Parameters:
Name Type Description
canvas

component

the target canvas.
x1,y1

real

start point.
x2,y2

real

control point 1.
x3,y3

real

control point 2.
x4,y4

real

end point.
Example
  1. registerAction('canvasAddBezier4Test', '', 'canvasAddBezier4Test', 'component:Canvas:canvas');
  2. function canvasAddBezier4Test(canvas) {
  3. setProperty(canvas, 'stroke_style', '#FF0000FF');
  4. setProperty(canvas, 'line_width', 4);
  5. canvasBeginPath(canvas);
  6. canvasAddMove(canvas, 150, 150);
  7. canvasAddBezier4(canvas, 150, 150, 175, 200, 180, 250, 140, 300);
  8. canvasDrawPathStroke(canvas);
  9. }

canvasAddEllipse(canvas, x, y, rx,ry)

canvasAddEllipse an ellipse at the x/y position with radiuses rx,ry added to the path
Parameters:
Name Type Description
canvas

component

the target canvas.
x

real

ellipse position.
y

real

ellipse position.
rx,ry

real

x and y radiuses (a circle if the same).
Example
  1. registerAction('canvasAddEllipseTest', '', 'canvasAddEllipseTest', 'component:Canvas:canvas');
  2. function canvasAddEllipseTest(canvas) {
  3. setProperty(canvas, 'stroke_style', '#FF0000');
  4. setProperty(canvas, 'line_width', 4);
  5. canvasBeginPath(canvas);
  6. canvasAddEllipse(canvas,200, 200, 50, 200, 50);
  7. canvasDrawPathStroke(canvas);
  8. }

canvasAddLine(canvas, x, y)

canvasAddLine a line from the current position to the new position on the current path. Note that this does not render immediately, it simply adds to the current path and displays when you draw the path.
Parameters:
Name Type Description
canvas

component

the target canvas.
x

real

new position.
y

real

new position.
Example
  1. registerAction('canvasAddLineTest', '', 'canvasAddLineTest', 'component:Canvas:canvas');
  2. function canvasAddLineTest(canvas) {
  3. setProperty(canvas, 'stroke_style', '#FF0000');
  4. setProperty(canvas, 'line_width', 4);
  5. canvasBeginPath(canvas);
  6. canvasAddMove(canvas, 100, 100);
  7. canvasAddLine(canvas, 150, 100);
  8. canvasAddLine(canvas, 150, 150);
  9. canvasAddLine(canvas, 100, 150);
  10. canvasClosePath(canvas);
  11. canvasDrawPathStroke(canvas);
  12. }

canvasAddMove(canvas, x, y)

canvasAddMove a move to a new position without drawing on a line. This does not have any immediate visual affect and simply sets up the position for where to start drawing the next command.
See canvasAddLine for example.
Parameters:
Name Type Description
canvas

component

the target canvas.
x

real

new x position.
y

real

new y position.

canvasAddRoundedRect(canvas, x1,y1, x2,y2, radius)

canvasAddRoundedRect a rounded rectangle from x1/y1 to x2/y2 with curved corners of radius is added to the path
Parameters:
Name Type Description
canvas

component

the target canvas.
x1,y1

real

top left corner of the rectangle.
x2,y2

real

bottom right corner of the rectangle.
radius

real

curvature of the corners.
Example
  1. registerAction('canvasAddRoundedRectTest', '', 'canvasAddRoundedRectTest', 'component:Canvas:canvas');
  2. function canvasAddRoundedRectTest(canvas) {
  3. setProperty(canvas, 'stroke_style', '#FF0000');
  4. setProperty(canvas, 'line_width', 4);
  5. canvasBeginPath(canvas);
  6. canvasAddRoundedRect(canvas, 200, 200, 100, 100, 20);
  7. canvasDrawPathStroke(canvas);
  8. }

canvasAddWedge(canvas, x, y, rx,ry, a1,a2, thickness_ratio)

canvasAddWedge a part of an ellipse with an inner and outer radius and starting and ending angle in degrees is added to the path
Parameters:
Name Type Description
canvas

component

the target canvas.
x

real

center of the wedge.
y

real

center of the wedge.
rx,ry

real

x and y radiuses (a circle if the same).
a1,a2

real

starting and ending angle in degrees.
thickness_ratio

real

0 is no thickness (just follows the circumference), 1 is a wedge right to the center of the ellipse, 0.5 is halfway.
Example
  1. registerAction('canvasAddWedgeTest', '', 'canvasAddWedgeTest', 'component:Canvas:canvas');
  2. function canvasAddWedgeTest(canvas) {
  3. setProperty(canvas, 'stroke_style', '#FF0000');
  4. setProperty(canvas, 'line_width', 4);
  5. canvasBeginPath(canvas);
  6. canvasAddWedge(canvas, 350, 350, 100, 100, 0, 90, 5); //degrees
  7. canvasDrawPathStroke(canvas);
  8. }

canvasAutoBrightnessContrast(canvas)

canvasAutoBrightnessContrast Automatically calculate and apply the maximum brightness and contrast
Parameters:
Name Type Description
canvas

component

the target canvas.
Example
  1. registerAction('canvasAutoBrightnessContrastTest', '', 'canvasAutoBrightnessContrastTest', 'component:Canvas:canvas');
  2. function canvasAutoBrightnessContrastTest(canvas) {
  3. canvasAutoBrightnessContrast(canvas);
  4. }

canvasAutoColor(canvas)

canvasAutoBrightnessContrast Automatically calculate and apply strong color saturation/balance
Parameters:
Name Type Description
canvas

component

the target canvas.
Example
  1. registerAction('canvasAutoColorTest', '', 'canvasAutoColorTest', 'component:Canvas:canvas');
  2. function canvasAutoColorTest(canvas) {
  3. canvasAutoColor(canvas);
  4. }

canvasBeginPath(canvas)

canvasBeginPath clears out the path buffer ready to add new commands. This does not have any immediate visual affect on its own. It is just used to prepare before other instructions.
See stroke for example.
Parameters:
Name Type Description
canvas

component

the target canvas.

canvasBoxBlur(canvas, radius)

canvasBoxBlur blurs the canvas
Parameters:
Name Type Description
canvas

component

the target canvas.
radius

int

radius of the blur in pixels.
Example
  1. registerAction('canvasBoxBlurTest', '', 'canvasBoxBlurTest', 'component:Canvas:canvas');
  2. function canvasBoxBlurTest(canvas) {
  3. canvasBoxBlur(canvas, 30);
  4. }

canvasBoxBlurRegion(canvas, x, y, w,-, h, radius)

canvasBoxBlurRegion blurs a region on the canvas
Parameters:
Name Type Description
canvas

component

the target canvas.
x

int

top left corner of the region.
y

int

top left corner of the region.
w,-

int

width of the region.
h

int

height of the region.
radius

int

radius of the blur in pixels.
Example
  1. registerAction('canvasBoxBlurRegionTest', '', 'canvasBoxBlurRegionTest', 'component:Canvas:canvas');
  2. function canvasBoxBlurRegionTest(canvas) {
  3. canvasBoxBlurRegion(canvas, 100, 100, 400, 400, 30);
  4. }

canvasCalcPsnr(canvas, othercanvas)

canvasCalcPsnr Returns the calculated peak signal to noise ratio comparing
an input canvas to another canvas.
The higher the returned value the more alike the images are. A typical value for
comparisons for lossy images are between 30 and 50 dB, where higher is better.
When the two images are identical, the resultant psnr will be infinity.
See http://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
Parameters:
Name Type Description
canvas

component

the target canvas.
othercanvas

component

the comparison canvas.
Example
  1. registerAction('canvasCalcPsnrTest', '', 'canvasCalcPsnrTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasCalcPsnrTest(canvas, canvas2) {
  3. var result = canvasCalcPsnr(canvas, canvas2);
  4. print('psnr = ',result);
  5. }

canvasCalculateTextWidth(canvas, text)

canvasCalculateTextWidth the specified text width is calculated without rendering
Parameters:
Name Type Description
canvas

component

the target canvas.
text

string

the text to render.
Returns:
width - the width of the text if it was rendered.
Type

real

Example
  1. registerAction('canvasCalculateTextWidthTest', '', 'canvasCalculateTextWidthTest', 'component:Canvas:canvas');
  2. function canvasCalculateTextWidthTest(canvas) {
  3. setProperty(canvas, 'stroke_style', '#FF0000FF');
  4. setProperty(canvas, 'font', '40px vera');
  5. setProperty(canvas, 'line_width', 2);
  6. var width = canvasCalculateTextWidth(canvas, 'Hello World');
  7. print('Text width = ',width);
  8. }

canvasChromaKey(canvas, hue, hue_mask, luminance_mask, mask_shadow, mask_light)

canvasChromaKey removes (known as a key) a specific color (or chroma). This function uses the HSV transform to calculate the hue (tint),
saturation (amount of tint) and value (brightness) - this allows us to control how much of the highlights and shadows are preserved when
a colored background is removed.
Parameters:
Name Type Description
canvas

component

the target canvas
hue

real

the color converted to hue (hsv) from 0 to 360, 0 red, 90 green, 180 blue
hue_mask

real

the hue tollerance to generate the mask, 0 to 1, 0.1 or 0.06 are good values
luminance_mask

real

the amount of luminance tollerance, 0 to 5, 1.5 is a good value
mask_shadow

real

the amount of shadow preserved, 0 to 5, 2.6 is a good value, smaller means less shadow is added
mask_light

real

the amount of saturated color preserved, 0 to 5, 0.9 is a good value, more means more highlights may be picked up
Example
  1. registerAction('canvasChromaKeyTest', '', 'canvasChromaKeyTest', 'component:Canvas:canvas');
  2. function canvasChromaKeyTest(canvas) {
  3. canvasChromaKey(canvas, 90, 0.06, 1.5, 2.6, 0.9);
  4. }

canvasClosePath(canvas)

canvasClosePath will draw the final line from your current position back to the start. This is a shortcut instead of doing a lineTo() and having to put in the correct numbers.
See canvasAddLine for example.
Parameters:
Name Type Description
canvas

component

the target canvas.

canvasCopyBuffer(canvas, canvas_src)

canvasCopyBuffer This is a high speed copy from one buffer to another, often used to reset a buffer during redraw operations
See canvasStampBuffer for a code example.
Parameters:
Name Type Description
canvas

component

the target canvas.
canvas_src

component

the source canvas.

canvasCreateNew(filename, width, height, color)

canvasCreateNew refreshes the canvas with a new image buffer. This resets the canvas removing any previous drawing on the canvas.
Parameters:
Name Type Description
filename

string

optional image, png, jpg, bmp or svg.
width

int

default width (used for svg or if no filename).
height

int

default height (used for svg or if no filename).
color

color

default color (used for svg or if no filename).
Returns:
width,height - the size of buffer allocated.
Type

json

Example
  1. registerAction('canvasCreateNewTest', '', 'canvasCreateNewTest', '');
  2. function canvasCreateNewTest() {
  3. //This creates a new canvas with a red background
  4. var canvas = findComponent('Page 21', 'canvas', 'Canvas 1');
  5. canvasCreateNew(canvas,'',1920,1080,'0xFF0000FF');
  6. //This creates a new canvas with an image
  7. var sz = canvasCreateNew(canvas,'button_01_default_9.png',0,0,'');
  8. sz = JSON.parse(sz);
  9. print(sz);
  10. }

canvasCrop(canvas, x, y, w, h)

canvasCrop will cut out the image at the specified size and location. The image of the canvas background then becomes this cutout.
The cropped image follows the same resize rules as the original (fit, fill, stretch).
This example will cut out a sqaure from your image starting at position (100,100) that is 200x200 pixels big.
This square becomes the new image background and will fill the canvas area.
Parameters:
Name Type Description
canvas

component

the target canvas.
x

int

the x position for the top left of where to crop.
y

int

the y position for the top left of where to crop.
w

int

the width of the area to be cropped.
h

int

the height of the area to be cropped.
Example
  1. registerAction('canvasCropTest', '', 'canvasCropTest', 'component:Canvas:canvas');
  2. function canvasCropTest(canvas) {
  3. canvasCrop(canvas, 100, 100,200,200);
  4. }

canvasDashAdd(canvas, on_length, off_length)

canvasDashAdd adds a dash on length and a dash off length which can be chained together to create patterns for stroke operations like canvasDrawTextStroke and canvasDrawPathStroke
Look at canvasDashClear for example code.
Parameters:
Name Type Description
canvas

component

the target canvas.
on_length

real

length of dash in pixels.
off_length

real

length of the gap in pixels.

canvasDashClear(canvas)

canvasDashClear clears any dashes for stroke operations like canvasDrawTextStroke and canvasDrawPathStroke
Parameters:
Name Type Description
canvas

component

the target canvas.
Example
  1. registerAction('canvasDashClearTest', '', 'canvasDashClearTest', 'component:Canvas:canvas');
  2. function canvasDashClearTest(canvas) {
  3. canvasBeginPath(canvas);
  4. setProperty(canvas, 'line_width', 4);
  5. canvasSetBrushColor(canvas, '0xFF0000FF');
  6. canvasAddMove(canvas, 100, 100);
  7. canvasAddLine(canvas, 250, 100);
  8. canvasAddLine(canvas, 250, 250);
  9. canvasAddLine(canvas, 100, 250);
  10. canvasClosePath(canvas);
  11. canvasDashAdd(canvas, 5, 15);
  12. canvasDrawPathStroke(canvas);
  13. canvasBeginPath(canvas);
  14. canvasDashClear(canvas);
  15. canvasAddMove(canvas, 100, 300);
  16. canvasAddLine(canvas, 250, 300);
  17. canvasAddLine(canvas, 250, 450);
  18. canvasAddLine(canvas, 100, 450);
  19. canvasClosePath(canvas);
  20. canvasDrawPathStroke(canvas);
  21. }

canvasDetectBlobs(canvas, r_similarity,g_similarity,b_similarity, blob_min_width, blob_min_size, visualise)

canvasDetectBlobs looks for pixel connected blobs which match a specific color
Parameters:
Name Type Description
canvas

component

the target canvas.
r_similarity,g_similarity,b_similarity

int

from 0 to 255 the 8 bit range (0 is an exact match, 255 matches all).
blob_min_width

int

the minium pixel width to be considered a blob (2 or higher).
blob_min_size

int

the minimum pixel count to be considered a blob (4 or higher).
visualise

int

if true lets you see the matches on the source canvas.
Returns:
blobs - for each blob the x,y,total is recorded
Type

json

Example
  1. var blobs = img_src.canvasDetectBlobs(canvas,0xFFFFFF,10,10,10,3,10,0)
  2. blobs = JSON.parse(blobs)
  3. for(var i = 0; i < blobs.length; i++) {
  4. var obj = blobs[i]
  5. var blobs_x = obj.x
  6. var blobs_y = obj.y
  7. var blobs_pixel_cnt = obj.total
  8. }

canvasDetectSegments(canvas, dst_canvas, num_elements, compactness, visualise)

canvasDetectSegments looks for pixel with a similar color and create (SNIC) superpixels into a result canvas with a unique color for each superpixel
Parameters:
Name Type Description
canvas

component

the target canvas.
dst_canvas

component

the canvas to hold the result.
num_elements

int

the number of superpixels (2 or higher).
compactness

real

0 to 100, the super pixels tendancy to circularity (10 is a common value).
visualise

int

if true lets you see the segments on the source canvas.
Example
  1. registerAction('canvasDetectSegmentsTest', '', 'canvasDetectSegmentsTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasDetectSegmentsTest(canvas, canvas2) {
  3. canvasDetectSegments(canvas, canvas2, 200, 10, 1);
  4. }

canvasDetectSlidingTemplate(canvas, canvas_template, template_x_count, x, y, slidex,slidey, slide_step)

canvasDetectSlidingTemplate slides a template over the canvas returning the best matching value and position for each template
Parameters:
Name Type Description
canvas

component

the target canvas.
canvas_template

component

the template canvas.
template_x_count

int

the canvas_template can have one or more templates left to right, they must all be the same width.
x

int

the x coordinate for the spot on the canvas to match the templates against.
y

int

the y coordinate for the spot on the canvas to match the templates against.
slidex,slidey

int

the number of pixels to slide in x and y to test the templates.
slide_step

int

by default 1 pixel, but can step in 2,3 or more pixel increments.
Returns:
template_matches - for each template the diff,x,y where the difference is the best match and x,y is the template position
Type

json

Example
  1. var templates = img_src.canvasDetectSlidingTemplate(canvas,template,10,100,100,3,3,1)
  2. templates = JSON.parse(templates)
  3. for(var i = 0; i < templates.length; i++) {
  4. var obj = templates[i]
  5. var difference = obj.dif
  6. var match_x = obj.x
  7. var match_y = obj.y
  8. }

canvasDrawPathFill(canvas)

canvasDrawPathFill the current path is drawn with the current brush in fill mode (fill in the middle)
Parameters:
Name Type Description
canvas

component

the target canvas.
Example
  1. registerAction('canvasDrawPathFillTest', '', 'canvasDrawPathFillTest', 'component:Canvas:canvas');
  2. function canvasDrawPathFillTest(canvas) {
  3. setProperty(canvas, 'fill_style', '#FF0000FF');
  4. canvasBeginPath(canvas);
  5. canvasAddRoundedRect(canvas, 200, 200, 100, 100, 20);
  6. canvasDrawPathFill(canvas);
  7. }

canvasDrawPathStroke(canvas)

canvasDrawPathStroke the current path is stroked with the current brush (draw the outside)
Parameters:
Name Type Description
canvas

component

the target canvas.
Example
  1. registerAction('canvasDrawPathStrokeTest', '', 'canvasDrawPathStrokeTest', 'component:Canvas:canvas');
  2. function canvasDrawPathStrokeTest(canvas) {
  3. setProperty(canvas, 'stroke_style', '#FF0000FF');
  4. setProperty(canvas, 'line_width', 20);
  5. //draw basic triangle with sharp corners
  6. canvasBeginPath(canvas);
  7. canvasAddMove(canvas, 100, 100);
  8. canvasAddLine(canvas, 250, 100);
  9. canvasAddLine(canvas, 100, 150);
  10. canvasClosePath(canvas);
  11. canvasDrawPathStroke(canvas);
  12. //draw triangle with curved corners
  13. canvasSetStrokeCap(canvas, 2); //the cap type 0 ButtCap, 1 SquareCap, 2 RoundCap
  14. canvasSetStrokeJoin(canvas, 2); //the join type 0 MiterJoin, 1 MiterJoinRevert, 2 RoundJoin, 3 BevelJoin, 4 MiterJoinRound
  15. canvasSetStrokeInnerJoin(canvas, 2);
  16. canvasSetStrokeInnerMiterLimit(canvas, 4);
  17. canvasSetStrokeMiterLimit(canvas, 4);
  18. canvasBeginPath(canvas);
  19. canvasAddMove(canvas, 100, 300);
  20. canvasAddLine(canvas, 250, 300);
  21. canvasAddLine(canvas, 100, 350);
  22. canvasClosePath(canvas);
  23. canvasDrawPathStroke(canvas);
  24. //draw triangle with flat corners
  25. canvasSetStrokeCap(canvas, 1); //the cap type 0 ButtCap, 1 SquareCap, 2 RoundCap
  26. canvasSetStrokeJoin(canvas, 3); //the join type 0 MiterJoin, 1 MiterJoinRevert, 2 RoundJoin, 3 BevelJoin, 4 MiterJoinRound
  27. canvasSetStrokeInnerJoin(canvas, 3);
  28. canvasSetStrokeInnerMiterLimit(canvas, 4);
  29. canvasSetStrokeMiterLimit(canvas, 4);
  30. canvasBeginPath(canvas);
  31. canvasAddMove(canvas, 100, 500);
  32. canvasAddLine(canvas, 250, 500);
  33. canvasAddLine(canvas, 100, 550);
  34. canvasClosePath(canvas);
  35. canvasDrawPathStroke(canvas);
  36. }

canvasDrawTextFill(canvas, text, x, y, width)

canvasDrawTextFill the specified text is drawn with the current brush in fill mode (fill in the middle)
Parameters:
Name Type Description
canvas

component

the target canvas.
text

string

the text to render.
x

real

the position of the top left corner.
y

real

the position of the top left corner.
width

real

the maximum width for the text to render into.
Example
  1. registerAction('canvasDrawTextFillTest', '', 'canvasDrawTextFillTest', 'component:Canvas:canvas');
  2. function canvasDrawTextFillTest(canvas) {
  3. setProperty(canvas, 'fill_style', '#FF0000FF');
  4. setProperty(canvas, 'font', '40px vera');
  5. canvasDrawTextFill(canvas, 'Hello World', 100, 100, 1000);
  6. }

canvasDrawTextStroke(canvas, text, x, y, width)

canvasDrawTextStroke the specified text is stroked with the current brush (draw the outside)
Parameters:
Name Type Description
canvas

component

the target canvas.
text

string

the text to render.
x

real

the position of the top left corner.
y

real

the position of the top left corner.
width

real

the maximum width for the text to render into.
Example
  1. registerAction('canvasDrawTextStrokeTest', '', 'canvasDrawTextStrokeTest', 'component:Canvas:canvas');
  2. function canvasDrawTextStrokeTest(canvas) {
  3. setProperty(canvas, 'stroke_style', '#FF0000FF');
  4. setProperty(canvas, 'font', '40px vera');
  5. setProperty(canvas, 'line_width', 2);
  6. canvasDrawTextStroke(canvas, 'Hello World', 100, 100, 1000);
  7. }

canvasFlipHorizontal(canvas)

canvasFlipHorizontal flip the target canvas horizontally.
Parameters:
Name Type Description
canvas

component

the target canvas.
Example
  1. registerAction('canvasFlipHorizontalTest', '', 'canvasFlipHorizontalTest', 'component:Canvas:canvas');
  2. function canvasFlipHorizontalTest(canvas) {
  3. canvasFlipHorizontal(canvas);
  4. }

canvasFlipVertical(canvas)

canvasFlipVertical flips the target canvas vertically.
Parameters:
Name Type Description
canvas

component

the target canvas.
Example
  1. registerAction('canvasFlipVerticalTest', '', 'canvasFlipVerticalTest', 'component:Canvas:canvas');
  2. function canvasFlipVerticalTest(canvas) {
  3. canvasFlipVertical(canvas);
  4. }

canvasGetHeight(canvas)

canvasGetHeight returns the canvas height. This is not the size of the component but the number of pixels the actual canvas was set to either from the background image or size specified.
Parameters:
Name Type Description
canvas

component

target canvas.
Returns:
height - the canvas height.
Type

int

Example
  1. registerAction('canvasGetHeightTest', '', 'canvasGetHeightTest', 'component:Canvas:canvas');
  2. function canvasGetHeightTest(canvas) {
  3. var Height = canvasGetHeight(canvas);
  4. print('Height = ',Height);
  5. }

canvasGetPixel(canvas, x, y)

canvasGetPixel returns the RGBA color value of th pixel at the given coordinates on the canvas. Out of bounds requests return the color transparent black.
Parameters:
Name Type Description
canvas

component

the canvas to read from.
x

int

pixel x position.
y

int

pixel y position.
Example
  1. registerAction('canvasGetPixelTest', '', 'canvasGetPixelTest', 'component:Canvas:canvas');
  2. function canvasGetPixelTest(canvas) {
  3. var pixelColor = canvasGetPixel(canvas, 250, 250);
  4. print('pixelColor = ',pixelColor);
  5. }

canvasGetPixelData(canvas)

canvasGetPixelData Retrieves all the binary pixel data in the canvas
To understand this data you will also need to look at width, height, pixel_stride and pixel_format properties
Parameters:
Name Type Description
canvas

component

the canvas
Example
  1. registerAction('canvasGetPixelDataTest', '', 'canvasGetPixelDataTest', 'component:Canvas:canvas');
  2. function canvasGetPixelDataTest(canvas) {
  3. var ArrayBuffer = canvasGetPixelData(canvas);
  4. var myDataView = new DataView(ArrayBuffer);
  5. myDataView.setInt16(0, 256, true);
  6. // Int16Array uses the platform's endianness.
  7. var dataArray = new Int16Array(ArrayBuffer)
  8. var isLittleEndian = dataArray[0] === 256;
  9. print('isLittleEndian = ',isLittleEndian);
  10. for(var i = 0; i < 20; i++) {
  11. var test = myDataView.getUint8(i);
  12. print('test = ',test);
  13. }
  14. }

canvasGetWidth(canvas)

canvasGetWidth returns the canvas width. This is not the size of the component but the number of pixels the actual canvas was set to either from the background image or size specified.
Parameters:
Name Type Description
canvas

component

target canvas.
Returns:
width - the canvas width.
Type

int

Example
  1. registerAction('canvasGetWidthTest', '', 'canvasGetWidthTest', 'component:Canvas:canvas');
  2. function canvasGetWidthTest(canvas) {
  3. var width = canvasGetWidth(canvas);
  4. print('Width = ',width);
  5. }

canvasGradientAddPoint(canvas, color, position)

canvasGradientAddPoint adds a color point at a position from 1-254. The multi point gradient starts with canvasSetBrushGradientStart, then any point gradients, then ends with canvasSetBrushGradientEnd. This gradient is used for brush operations like canvasDrawPathFill and canvasDrawPathStroke
See canvasGradientClear for a code example.
Parameters:
Name Type Description
canvas

component

the target canvas.
color

color

the color point to add.
position

int

from 1 to 254 (e.g. 128 will be a middle color between the start and end colors).

canvasGradientClear(canvas)

canvasGradientClear clears any point gradients for brush operations like canvasDrawPathFill and canvasDrawPathStroke
This clears away your gradient settings such as colors but does not stop it being in gradient mode. You must use canvasSetBrushMode to set it back to 0 to return to a normal non-gradient mode.
Parameters:
Name Type Description
canvas

component

the target canvas
Example
  1. registerAction('canvasGradientClearTest', '', 'canvasGradientClearTest', 'component:Canvas:canvas');
  2. function canvasGradientClearTest(canvas) {
  3. canvasBeginPath(canvas);
  4. canvasSetBrushPosition(canvas,0,0)
  5. canvasSetBrushGradientStart(canvas, '0x0000FFFF'); //center colour of the diamond gradient
  6. canvasSetBrushGradientEnd(canvas, '0x00FF00FF'); //outer colour of the diamond gradient
  7. canvasGradientAddPoint(canvas, '0xFF0000FF', 400);
  8. canvasSetBrushMode(canvas, 3); //look at the BrushMode property for more gradient options.
  9. canvasAddMove(canvas, 0, 100);
  10. canvasAddLine(canvas, 1000, 100);
  11. canvasAddLine(canvas, 1000, 250);
  12. canvasAddLine(canvas, 0, 250);
  13. canvasClosePath(canvas);
  14. canvasDrawPathFill(canvas);
  15. //This is setting the size of the rectangle to the size of the canvas
  16. canvasGradientClear(canvas);
  17. canvasBeginPath(canvas);
  18. canvasAddMove(canvas, 0, 300);
  19. canvasAddLine(canvas, 1000, 300);
  20. canvasAddLine(canvas, 1000, 450);
  21. canvasAddLine(canvas, 0, 450);
  22. canvasClosePath(canvas);
  23. canvasDrawPathFill(canvas);
  24. //reset mode back to default for future operations
  25. canvasSetBrushMode(canvas, 0);
  26. }

canvasHsv(canvas, hue, saturation, value)

canvasHsv Adjusts the canvas with an HSV transform. HSV provides control over the hue (tint),
saturation (amount of tint) and value (brightness) giving control of the amount of color in the image
Parameters:
Name Type Description
canvas

component

the target canvas
hue

real

0 no change, (-180 to 180), each 90 plus and minus is a change in RGB hue
saturation

real

0 no change, (-1 to 1) -1 = desaturated, 1 = saturated
value

real

0 no change, (-1 to 1) -1 = dark, 1 = bright
Example
  1. registerAction('canvasHsvTest', '', 'canvasHsvTest', 'component:Canvas:canvas');
  2. function canvasHsvTest(canvas) {
  3. canvasHsv(canvas, 90, 0.5, 0.5);
  4. }

canvasInvert(canvas)

canvasInvert inverts the colors in the canvas.
Parameters:
Name Type Description
canvas

component

the canvas to invert.
Example
  1. registerAction('canvasInvertTest', '', 'canvasInvertTest', 'component:Canvas:canvas');
  2. function canvasInvertTest(canvas) {
  3. canvasInvert(canvas);
  4. }

canvasLighting(canvas, brightness, contrast, shadow, fill, highlight, temperature)

canvasLighting apply lighting to the canvas
Parameters:
Name Type Description
canvas

component

the target canvas
brightness

real

(-1 to 1) -1 = black, 0 = unmodified, 1 = white
contrast

real

(-1 to 1) -1 = no contrast / grey, 0 = unmodified, 1 = high contrast
shadow

real

(-1 to 1) -1 = shadow reduced, 0 = unmodified, 1 = shadow increased
fill

real

(-1 to 1) -1 = fill light reduced, 0 = unmodified, 1 = fill light increased
highlight

real

(-1 to 1) -1 = highlights reduced / grey, 0 = unmodified, 1 = highlights increased
temperature

real

(-1 to 1) -1 = warm / red, 0 = unmodified, 1 = cool / blue
Example
  1. registerAction('canvasLightingTest', '', 'canvasLightingTest', 'component:Canvas:canvas');
  2. function canvasLightingTest(canvas) {
  3. canvasLighting(canvas, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5);
  4. }

canvasPrepareSvg(canvas, filename, svgdata)

canvasPrepareSvg preload an SVG ready to be stamped onto the canvas canvasStampSvg. This has no immediate visual effect and is just a preparation but will display once you stamp it onto the canvas.
Parameters:
Name Type Description
canvas

component

the target canvas.
filename

string

the svg file from the images folder.
svgdata

string

an alternative svg string to render.
Returns:
dimensions -JSON data of the top left and bottom right coordinates of the svg prepared.
Type

string

Example
  1. registerAction('canvasPrepareSvgTest', '', 'canvasPrepareSvgTest', 'component:Canvas:canvas');
  2. function canvasPrepareSvgTest(canvas) {
  3. canvasPrepareSvg(canvas, 'soccerbelgium.svg', '');
  4. }

canvasReadAprilTags(canvas)

canvasReadAprilTags scans the canvas for april tags and tries to read in their data.
Parameters:
Name Type Description
canvas

component

the target canvas.
Returns:
tagslist - id,margin,x,y,tl,tr,br,bl (The tag ID, the accuracy margin, the x/y center, the TopLeft, TopRight, BottomRight and BottomLeft corners of the tag)
Type

json

Example
  1. registerAction('canvasReadAprilTagsTest', '', 'canvasReadAprilTagsTest', 'component:Canvas:canvas');
  2. function canvasReadAprilTagsTest(canvas) {
  3. setProperty(canvas, 'font', '40px vera');
  4. var tags = canvasReadAprilTags(canvas);
  5. tags = JSON.parse(tags);
  6. print('!m1 tags = ',tags);
  7. setProperty(canvas, 'stroke_style', '#FF0000');
  8. setProperty(canvas, 'line_width', 4);
  9. for(var i = 0; i < tags.length; i++) {
  10. var obj = tags[i];
  11. canvasBeginPath(canvas);
  12. canvasAddMove(canvas, obj.tl_x, obj.tl_y);
  13. canvasAddLine(canvas, obj.tr_x, obj.tr_y);
  14. canvasAddLine(canvas, obj.br_x, obj.br_y);
  15. canvasAddLine(canvas, obj.bl_x, obj.bl_y);
  16. canvasAddLine(canvas, obj.tl_x, obj.tl_y);
  17. canvasDrawPathStroke(canvas);
  18. canvasDrawTextFill(canvas, obj.id, obj.x, obj.y-50, 1000);
  19. }
  20. }

canvasReadBarcode(canvas)

canvasReadBarcode scans the canvas for a barcode and attempts to read in the data if it finds one.
Parameters:
Name Type Description
canvas

canvas

target canvas.
Returns:
code - the data encoded in the barcode.
Type

string

Example
  1. registerAction('canvasReadBarcodeTest', '', 'canvasReadBarcodeTest', 'component:Canvas:canvas');
  2. function canvasReadBarcodeTest(canvas) {
  3. var data = canvasReadBarcode(canvas);
  4. print('data = ',data,' len = ',data.length);
  5. }

canvasReadQrcode(canvas)

canvasReadQrcode reads a potential QR code on the canvas
Parameters:
Name Type Description
canvas

canvas

target canvas.
Returns:
code - the data encoded.
Type

string

Example
  1. registerAction('canvasReadQrcodeTest', '', 'canvasReadQrcodeTest', 'component:Canvas:canvas');
  2. function canvasReadQrcodeTest(canvas) {
  3. var data = canvasReadQrcode(canvas);
  4. print('data = ',data,' len = ',data.length);
  5. }

canvasResetColor(canvas, color)

canvasResetColor quickly updates the whole canvas to the specified color
Parameters:
Name Type Description
canvas

component

the target canvas.
color

color

the color to apply to the canvas.
Example
  1. registerAction('canvasResetColorTest', '', 'canvasResetColorTest', 'component:Canvas:canvas');
  2. function canvasResetColorTest(canvas) {
  3. canvasResetColor(canvas, '0x448844FF');
  4. }

canvasResetTransform(canvas)

canvasResetTransform updates the transform back to it's default value (unity). Look at canvasRotateTransform for example code using this.
Parameters:
Name Type Description
canvas

component

the target canvas.

canvasResize(canvas, w, h, horz_filter, vert_filter)

canvasResize Resizes the canvas which will also recreate the canvas clearing away anything that had been drawn to the canvas.
This resizes the actual canvas itself affecting the number of pixels available. This means if you resize to be a lot
smaller the display will be the same size but the image will be blury as the canvas stretches to fit the component.
Parameters:
Name Type Description
canvas

component

the target canvas.
w

int

the width to resize to.
h

int

the height to resize to.
horz_filter

int

0 nearest, 1 linear, 2 avg, 3 lanzcos.
vert_filter

int

0 nearest, 1 linear, 2 avg, 3 lanzcos.
Example
  1. registerAction('canvasResizeTest', '', 'canvasResizeTest', 'component:Canvas:canvas');
  2. function canvasResizeTest(canvas) {
  3. canvasResize(canvas, 100, 100, 0, 0);
  4. }

canvasRotate(canvas, mode)

canvasRotate Rotates the canvas in 90 degree increments. This operation is additive. Calling it twice with mode 1 with result in a total of 180 degree rotation.
Parameters:
Name Type Description
canvas

component

the target canvas.
mode

int

Rotates the canvas by a given angle (0 = no rotate, 1 = 90 degrees, 2 = 180, 3 = 270).
Example
  1. registerAction('canvasRotateTest', '', 'canvasRotateTest', 'component:Canvas:canvas');
  2. function canvasRotateTest(canvas) {
  3. canvasRotate(canvas, 1); //1 means 90 degrees
  4. }

canvasRotateTransform(canvas, angle)

canvasRotateTransform updates the transform rotation for the current path - this will be applied during canvasDrawPathFill or canvasDrawPathStroke
Parameters:
Name Type Description
canvas

component

the target canvas.
angle

string

the angle in degrees to rotate.
Example
  1. registerAction('canvasRotateTransformTest', '', 'canvasRotateTransformTest', 'component:Canvas:canvas');
  2. function canvasRotateTransformTest(canvas) {
  3. //draw normal shape
  4. setProperty(canvas, 'stroke_style', '#FF0000FF');
  5. setProperty(canvas, 'line_width', 4);
  6. canvasBeginPath(canvas);
  7. canvasAddRoundedRect(canvas, 200, 100, 100, 100, 20);
  8. canvasDrawPathStroke(canvas);
  9. //draw rotated shape
  10. setProperty(canvas, 'stroke_style', '#FF0000FF');
  11. setProperty(canvas, 'line_width', 4);
  12. canvasBeginPath(canvas);
  13. canvasRotateTransform(canvas, 45); //applies rotation in degrees
  14. canvasAddRoundedRect(canvas, 200, 100, 100, 100, 20);
  15. canvasDrawPathStroke(canvas);
  16. canvasResetTransform(canvas); //removes the transform rotate for future operations.
  17. }

canvasSaveAs(canvas, filename, quality)

canvasSaveAs saves a render of the canvas as an image to storage.
Parameters:
Name Type Description
canvas

component

the target canvas.
filename

string

the path and filename with extension .png or .jpg.
quality

real

the jpeg or png compression ratio from 0-1.
Example
  1. registerAction('canvasSaveAsTest', '', 'canvasSaveAsTest', 'component:Canvas:canvas');
  2. function canvasSaveAsTest(canvas) {
  3. canvasSaveAs(canvas, 'test.png', 0.9);
  4. }

canvasScaleTransform(canvas, sx,sy)

canvasScaleTransform updates the transform scale for the current path - this will be applied during canvasDrawPathFill or canvasDrawPathStroke
Parameters:
Name Type Description
canvas

component

the target canvas.
sx,sy

string

the scale in the x and y directions (1 = normal scale, -1 = negative scale, 0.5 = half scale, 2.0 = double scale).
Example
  1. registerAction('canvasScaleTransformTest', '', 'canvasScaleTransformTest', 'component:Canvas:canvas');
  2. function canvasScaleTransformTest(canvas) {
  3. //draw normal shape
  4. setProperty(canvas, 'stroke_style', '#FF0000FF');
  5. setProperty(canvas, 'line_width', 4);
  6. canvasBeginPath(canvas);
  7. canvasAddRoundedRect(canvas, 200, 100, 100, 100, 20);
  8. canvasDrawPathStroke(canvas);
  9. //draw scaled shape
  10. setProperty(canvas, 'stroke_style', '#FF0000FF');
  11. setProperty(canvas, 'line_width', 4);
  12. canvasBeginPath(canvas);
  13. canvasScaleTransform(canvas, 0.5, 0.5); //applies scale in percentage
  14. canvasAddRoundedRect(canvas, 200, 100, 100, 100, 20);
  15. canvasDrawPathStroke(canvas);
  16. canvasResetTransform(canvas); //removes the transform scale for future operations.
  17. }

canvasSetBrushAngle(canvas, angle)

canvasSetBrushAngle sets the brush angle for image mode operations like canvasDrawPathStroke and canvasDrawPathFill
See canvasSetBrushMode for example of a gradient being set on an angle.
Parameters:
Name Type Description
canvas

component

the target canvas.
angle

real

the image angle in degrees.

canvasSetBrushBlendMode(canvas, blendmode)

canvasSetBrushBlendMode sets the brush mode for operations like canvasDrawPathStroke and canvasDrawPathFill
Look at canvasStampBarcode for example code.
Parameters:
Name Type Description
canvas

component

the target canvas.
blendmode

int

the brush blendmodes are 0 NoBlend, 1 Src, 2 Dst, 3 SrcOver, 4 DstOver, 5 SrcIn, 6 DstIn, 7 SrcOut, 8 DstOut, 9 SrcATop, 10 DstATop, 11 XOR, 12 Plus, 13 Minus, 14 Multiply, 16 Screen, 17 Overlay, 18 Darken, 19 Lighten, 20 Dodge, 21 Burn, 22 Hardlight, 23 Softlight, 24 Difference, 25 Exclusion, 26 contrast, 27 invert, 28 invertRGB.

canvasSetBrushColor(canvas, color)

canvasSetBrushColor sets the brush color for operations like canvasDrawPathStroke and canvasDrawPathFill
Instead you can use setProperty(canvas, 'stroke_style', '#FF0000FF'); or setProperty(canvas, 'fill_style', '#FF0000FF');
These will set the color for pathStroke and pathFill separately where as canvasSetBrushColor sets the color for both.
Parameters:
Name Type Description
canvas

component

the target canvas.
color

color

the color for the brush.
Example
  1. registerAction('canvasSetBrushColorTest', '', 'canvasSetBrushColorTest', 'component:Canvas:canvas');
  2. function canvasSetBrushColorTest(canvas) {
  3. canvasSetBrushColor(canvas, '00FF00FF');
  4. setProperty(canvas, 'line_width', 20);
  5. canvasBeginPath(canvas);
  6. canvasAddMove(canvas, 100, 100);
  7. canvasAddLine(canvas, 250, 100);
  8. canvasAddLine(canvas, 100, 150);
  9. canvasClosePath(canvas);
  10. canvasDrawPathStroke(canvas);
  11. }

canvasSetBrushGradientEnd(canvas, color_start)

canvasSetBrushGradientEnd sets the brush end gradient color for operations like canvasDrawPathStroke and canvasDrawPathFill
Look at canvasGradientClear for example code.
Parameters:
Name Type Description
canvas

component

the target canvas.
color_start

color

the end gradient color.

canvasSetBrushGradientStart(canvas, color_start)

canvasSetBrushGradientStart sets the brush start gradient color for operations like canvasDrawPathStroke and canvasDrawPathFill
Look at canvasGradientClear for example code.
Parameters:
Name Type Description
canvas

component

the target canvas.
color_start

color

the start gradient color.

canvasSetBrushMode(canvas, mode)

canvasSetBrushMode sets the brush mode for operations like canvasDrawPathStroke and canvasDrawPathFill
Parameters:
Name Type Description
canvas

component

the target canvas.
mode

int

the brush modes are 0 Uniform, 1 ImageClip, 2 ImageRepeat, 3 LinearGradient, 4 RadialGradient, 5 ConicGradient, 6 DiamondGradient.
Example
  1. registerAction('canvasSetBrushModeTest', '', 'canvasSetBrushModeTest', 'component:Canvas:canvas');
  2. function canvasSetBrushModeTest(canvas) {
  3. var pixelWidth = canvasGetWidth(canvas);
  4. var pixelHeight = canvasGetHeight(canvas);
  5. canvasBeginPath(canvas);
  6. canvasSetBrushScale(canvas, 1.5, 1.5); //this increases the size of the central diamond gradient shape
  7. canvasSetBrushGradientStart(canvas, '0x0000FFFF'); //center colour of the diamond gradient
  8. canvasSetBrushGradientEnd(canvas, '0x00FF00FF'); //outer colour of the diamond gradient
  9. canvasSetBrushMode(canvas, 6); //look at the BrushMode property for more gradient options.
  10. canvasSetBrushPosition(canvas, pixelWidth/2, pixelHeight/2); //This is setting the center of the diamond gradient shape to the center of the canvas
  11. canvasSetBrushAngle(canvas, 45); //This rotates the diamond gradient by 45 degrees.
  12. //This is setting the size of the rectangle to the size of the canvas
  13. canvasAddMove(canvas, 0, 0);
  14. canvasAddLine(canvas, pixelWidth, 0);
  15. canvasAddLine(canvas, pixelWidth, pixelHeight);
  16. canvasAddLine(canvas, 0, pixelHeight);
  17. canvasClosePath(canvas);
  18. canvasDrawPathFill(canvas);
  19. //undo the gradient options set here so future operations are not affected by it
  20. canvasGradientClear(canvas);
  21. }

canvasSetBrushPointSample(canvas, pointsamplemode)

canvasSetBrushPointSample sets the brush to pointsample - this is used for sampling barcodes and other hard edged images.
Used before making canvasStampBarcode() calls or other image stamping functions.
See canvasStampBarcodeTest for example.
Parameters:
Name Type Description
canvas

component

the target canvas.
pointsamplemode

bool

Normally false, but set to true for barcodes and other hard edged images.

canvasSetBrushPosition(canvas, x, y)

canvasSetBrushPosition sets the brush position for image mode operations like canvasDrawPathStroke and canvasDrawPathFill
See canvasSetBrushMode for example of a gradient being set on an angle.
Parameters:
Name Type Description
canvas

component

the target canvas.
x

real

the image x position.
y

real

the image y position.

canvasSetBrushScale(canvas, sx,sy)

canvasSetBrushScale sets the brush scale for image mode operations like canvasDrawPathStroke and canvasDrawPathFill
See canvasSetBrushMode for example of a gradient being set on an angle.
Parameters:
Name Type Description
canvas

component

the target canvas.
sx,sy

real

the image scale x and scale y.

canvasSetBrushSource(canvas, canvas_source)

canvasSetBrushSource sets the brush image source for operations like canvasDrawPathStroke and canvasDrawPathFill
Parameters:
Name Type Description
canvas

component

the target canvas.
canvas_source

component

the source canvas to use for the brush.
Example
  1. registerAction('canvasSetBrushSourceTest', '', 'canvasSetBrushSourceTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasSetBrushSourceTest(canvas, canvas2) {
  3. canvasBeginPath(canvas);
  4. canvasSetBrushSource(canvas, canvas2);
  5. canvasSetBrushSourceTopLeft(canvas, 100, 100);
  6. canvasSetBrushSourceBottomRight(canvas, 300, 300);
  7. canvasSetBrushMode(canvas, 2);
  8. canvasAddMove(canvas, 100, 100);
  9. canvasAddLine(canvas, 550, 100);
  10. canvasAddLine(canvas, 550, 550);
  11. canvasAddLine(canvas, 100, 550);
  12. canvasClosePath(canvas);
  13. canvasDrawPathFill(canvas);
  14. }

canvasSetBrushSourceBottomRight(canvas, x, y)

canvasSetBrushSourceBottomRight sets the brush bottom right clip for image mode operations like canvasDrawPathStroke and canvasDrawPathFill
See canvasSetBrushSource for example code of how to use this.
Parameters:
Name Type Description
canvas

component

the target canvas.
x

real

the image bottom right clip position.
y

real

the image bottom right clip position.

canvasSetBrushSourceTopLeft(canvas, x, y)

canvasSetBrushSourceTopLeft sets the brush top left clip for image mode operations like canvasDrawPathStroke and canvasDrawPathFill
See canvasSetBrushSource for example code of how to use this.
Parameters:
Name Type Description
canvas

component

the target canvas.
x

real

the image top left clip position.
y

real

the image top left clip position.

canvasSetFontFilename(canvas, filename)

canvasSetFontFilename sets the font for operations like canvasDrawTextStroke and canvasDrawTextFill
Parameters:
Name Type Description
canvas

component

the target canvas.
filename

string

the filename of a ttf or otf font in the project fonts folder.
Example
  1. registerAction('canvasSetFontFilenameTest', '', 'canvasSetFontFilenameTest', 'component:Canvas:canvas');
  2. function canvasSetFontFilenameTest(canvas) {
  3. canvasSetFontFilename(canvas, "vera.ttf");
  4. canvasSetFontHeight(canvas, 60);
  5. setProperty(canvas, 'fill_style', '#FF0000FF');
  6. canvasDrawTextFill(canvas, 'Hello World', 100, 100, 1000);
  7. }

canvasSetFontHeight(canvas, height)

canvasSetFontFilename sets the font height for operations like canvasDrawTextStroke and canvasDrawTextFill
Look at canvasSetFontFilename for example code.
Parameters:
Name Type Description
canvas

component

the target canvas.
height

real

the font height in pixels.

canvasSetPixel(canvas, x, y, color)

canvasSetPixel sets the color of the pixel at the given coordinates on the canvas to the specified color.
Parameters:
Name Type Description
canvas

component

the canvas to update.
x

int

pixel x position.
y

int

pixel y position.
color

color

pixel RGBA color.
Example
  1. registerAction('canvasSetPixelTest', '', 'canvasSetPixelTest', 'component:Canvas:canvas');
  2. function canvasSetPixelTest(canvas) {
  3. //This makes a thick red line at the top left of the canvas 4 pixels tall and 75 pixels across placed 10 pixels in from the edges.
  4. for (i = 0; i < 75; i++) {
  5. canvasSetPixel(canvas, 10+i, 10, 0xFF0000FF);
  6. canvasSetPixel(canvas, 10+i, 11, 0xFF0000FF);
  7. canvasSetPixel(canvas, 10+i, 12, 0xFF0000FF);
  8. canvasSetPixel(canvas, 10+i, 13, 0xFF0000FF);
  9. }
  10. }

canvasSetPixelData(canvas, data, format)

canvasSetPixelData Sets new pixel data to the canvas in specified format
Parameters:
Name Type Description
canvas

component

the canvas.
data

ArrayBuffer

the pixel data.
format

int

pixel data format.
Example
  1. registerAction('canvasSetPixelDataTest', '', 'canvasSetPixelDataTest', 'component:Canvas:canvas');
  2. function canvasSetPixelDataTest(canvas) {
  3. var ArrayBuffer = canvasGetPixelData(canvas);
  4. var myDataView = new DataView(ArrayBuffer);
  5. myDataView.setInt16(0, 256, true);
  6. for(var i = 4; i < ctx.pixelStride*5; i+=4) { //5 rows of data written as blue (starts at bottom left of image)
  7. myDataView.setUint8(i, 0);
  8. myDataView.setUint8(i+1, 0);
  9. myDataView.setUint8(i+3, 255);
  10. }
  11. var width = 1000;
  12. var height = 978;
  13. var stride = ctx.pixelStride;
  14. var format = 4; //'RGBA'
  15. var resultData = myDataView.buffer;
  16. canvasSetPixelData(canvas, width, height, stride, format, resultData);
  17. }

canvasSetStrokeCap(canvas, cap_type)

canvasSetStrokeCap sets the brush cap for stroke operations like canvasDrawPathStroke
Parameters:
Name Type Description
canvas

component

the target canvas.
cap_type

int

the cap type 0 ButtCap, 1 SquareCap, 2 RoundCap.

canvasSetStrokeInnerJoin(canvas, join_type)

canvasSetStrokeInnerJoin sets the brush inner join for stroke operations like canvasDrawPathStroke
Parameters:
Name Type Description
canvas

component

the target canvas.
join_type

int

the join type 0 InnerBevel, 1 InnerMiter, 2 InnerJag, 3 InnerRound.

canvasSetStrokeInnerMiterLimit(canvas, limit)

canvasSetStrokeInnerMiterLimit sets the brush inner miter limit for stroke operations like canvasDrawPathStroke
Parameters:
Name Type Description
canvas

component

the target canvas.
limit

real

the inner miter limit in degrees.

canvasSetStrokeJoin(canvas, join_type)

canvasSetStrokeJoin sets the brush join for stroke operations like canvasDrawPathStroke
Parameters:
Name Type Description
canvas

component

the target canvas.
join_type

int

the join type 0 MiterJoin, 1 MiterJoinRevert, 2 RoundJoin, 3 BevelJoin, 4 MiterJoinRound.

canvasSetStrokeMiterLimit(canvas, limit)

canvasSetStrokeMiterLimit sets the brush miter limit for stroke operations like canvasDrawPathStroke
Parameters:
Name Type Description
canvas

component

the target canvas.
limit

real

the miter limit in degrees.

canvasSetStrokeWidth(canvas, width)

canvasSetStrokeWidth sets the brush width for stroke operations like canvasDrawPathStroke
Parameters:
Name Type Description
canvas

component

the target canvas.
width

real

the width in pixels of the stroke.
Example
  1. registerAction('canvasSetStrokeWidthTest', '', 'canvasSetStrokeWidthTest', 'component:Canvas:canvas');
  2. function canvasSetStrokeWidthTest(canvas) {
  3. setProperty(canvas, 'stroke_style', '#FF0000FF');
  4. canvasSetStrokeWidth(canvas, 8);
  5. canvasBeginPath(canvas);
  6. canvasAddRoundedRect(canvas, 200, 100, 100, 100, 20);
  7. canvasDrawPathStroke(canvas);
  8. }

canvasSkewTransform(canvas, sx,sy)

canvasSkewTransform updates the transform skew for the current path - this will be applied during canvasDrawPathFill or canvasDrawPathStroke
Parameters:
Name Type Description
canvas

component

the target canvas.
sx,sy

string

the skew in the x and y directions (can be negative or positive).
Example
  1. registerAction('canvasSkewTransformTest', '', 'canvasSkewTransformTest', 'component:Canvas:canvas');
  2. function canvasSkewTransformTest(canvas) {
  3. //draw normal shape
  4. setProperty(canvas, 'stroke_style', '#FF0000FF');
  5. setProperty(canvas, 'line_width', 4);
  6. canvasBeginPath(canvas);
  7. canvasAddRoundedRect(canvas, 200, 100, 100, 100, 20);
  8. canvasDrawPathStroke(canvas);
  9. //draw skewed shape
  10. setProperty(canvas, 'stroke_style', '#FF0000FF');
  11. setProperty(canvas, 'line_width', 4);
  12. canvasBeginPath(canvas);
  13. canvasSkewTransform(canvas, 45, 45); //applies skew in degrees
  14. canvasAddRoundedRect(canvas, 200, 100, 100, 100, 20);
  15. canvasDrawPathStroke(canvas);
  16. canvasResetTransform(canvas); //removes the transform skew for future operations.
  17. }

canvasSmoothPath(canvas, steps)

canvasSmoothPath converts lines on a path into a bezier curve.
Parameters:
Name Type Description
canvas

component

the target canvas.
steps

real

number of steps of smoothing (0 to 2).
Example
  1. registerAction('canvasSmoothPathTest', '', 'canvasSmoothPathTest', 'component:Canvas:canvas');
  2. function canvasSmoothPathTest(canvas) {
  3. canvasResetColor(canvas, '0x448844FF'); //sets the canvas bg color to green
  4. setProperty(canvas, 'stroke_style', '#0000FFFF'); //sets the drawing color to blue
  5. canvasAddMove(canvas,100,Math.cos(0.0)*190+500);
  6. for (i = 0; i < 15; i++) {
  7. canvasAddLine(canvas,i*50 + 100,Math.cos(i)*190 + 500);
  8. }
  9. //draw jagged lines
  10. canvasDrawPathStroke(canvas);
  11. //now smooth and draw smooth curve below
  12. canvasSmoothPath(canvas,2);
  13. canvasTranslateTransform(canvas,0,200);
  14. canvasDrawPathStroke(canvas);
  15. canvasResetTransform(canvas);
  16. }

canvasStampAdaptiveThreshold(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y, strength, radius, blend)

canvasStampAdaptiveThreshold thresholds with variable strength given a radius of local contrast. The blend 0-1 is how much of the image is preserved vs thresholded.
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

int

the source top left
src_width,src_height

int

the source width and height
dst_x,dst_y

int

the destination position top left
strength

real

-1 to 1 how strong the threshold is towards binary
radius

int

1 to 1000 how wide the radius to check for local contrast
blend

real

0 to 1 how much of the image is preserved vs thresholded (0.5 is a common value)
Example
  1. registerAction('canvasStampAdaptiveThresholdTest', '', 'canvasStampAdaptiveThresholdTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampAdaptiveThresholdTest(canvas, canvas2) {
  3. var pixelWidth = canvasGetWidth(canvas2);
  4. var pixelHeight = canvasGetHeight(canvas2);
  5. canvasStampAdaptiveThreshold(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0, 0.2, 10, 0.5);
  6. }

canvasStampAutoBrightnessContrast(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y)

canvasStampAutoBrightnessContrast stamp a source canvas region onto the target canvas while calculating and applying the maximum brightness and contrast
Parameters:
Name Type Description
canvas

component

the target canvas.
canvas_src

component

the source canvas.
src_x,src_y

int

the source top left.
src_width,src_height

int

the source width and height.
dst_x,dst_y

int

the destination position top left.
Example
  1. registerAction('canvasStampAutoBrightnessContrastTest', '', 'canvasStampAutoBrightnessContrastTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampAutoBrightnessContrastTest(canvas, canvas2) {
  3. var pixelWidth = canvasGetWidth(canvas2);
  4. var pixelHeight = canvasGetHeight(canvas2);
  5. canvasStampAutoBrightnessContrast(canvas, canvas2, 0, 0, pixelWidth-1, pixelHeight-1, 0, 0);
  6. }

canvasStampAutoColor(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y)

canvasStampAutoColor stamp a source canvas region onto the target canvas while calculating and applying strong color saturation/balance
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

int

the source top left
src_width,src_height

int

the source width and height
dst_x,dst_y

int

the destination position top left
Example
  1. registerAction('canvasStampAutoColorTest', '', 'canvasStampAutoColorTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampAutoColorTest(canvas, canvas2) {
  3. var pixelWidth = canvasGetWidth(canvas2);
  4. var pixelHeight = canvasGetHeight(canvas2);
  5. canvasStampAutoColor(canvas, canvas2, 0, 0, pixelWidth-1, pixelHeight-1, 0, 0);
  6. }

canvasStampAvgDelta(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y, min_alpha)

canvasStampAvgDelta combines a target image with a source image. This averages the two images together. Repeated calls to this function
drawing the source over the destination will creep closer towards the source by half each time. Writing new images will display a rolling
average with each historic frame being half the next, useful for blending and for motion detection.
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

int

the source top left
src_width,src_height

int

the source width and height
dst_x,dst_y

int

the destination position top left
min_alpha

int

(0 to 255) can be used to stop the alpha from be averaged to zero
Example
  1. registerAction('canvasStampAvgDeltaTest', '', 'canvasStampAvgDeltaTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampAvgDeltaTest(canvas, canvas2) {
  3. var pixelWidth = canvasGetWidth(canvas2);
  4. var pixelHeight = canvasGetHeight(canvas2);
  5. canvasStampAvgDelta(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0, 0);
  6. }

canvasStampBarcode(canvas, code, x, y, angle, size, codetype, codelevel)

canvasStampBarcode stamp a 1D or 2D barcode onto the canvas.
Parameters:
Name Type Description
canvas

component

the target canvas.
code

string

the text/numbers to encode (note only some barcodes such as Aztec, QR, PDF417 support letters).
x

real

the x position for the top left of where to put the barcode.
y

real

the y position for the top left of where to put the barcode.
angle

real

the angle in degrees.
size

real

size from 1-100 pixels per bar.
codetype

int

the barcode (Aztec=1, Codeabar=2, Code39=4, code93=8, code128=16, dataMatrix=32, EAN8=64, EAN13=128, ITF=256, Maxicode=512, PDF417=1024, QRcode=2048, RSS14=4096, RSSE=8192, UPCA=16384, UPCE=32768).
codelevel

int

Some codes support redundancy levels, 1=low, 4=medium, 7=high.
Example
  1. registerAction('canvasStampBarcodeTest', '', 'canvasStampBarcodeTest', 'component:Canvas:canvas');
  2. function canvasStampBarcodeTest(canvas) {
  3. canvasSetBrushPointSample(canvas, true);
  4. canvasSetBrushBlendMode(canvas, 3);
  5. canvasStampBarcode(canvas, "Text to user",180,180,0,17,uComps.StampCodeType.AZTEC,0);
  6. canvasStampBarcode(canvas, "123456",780,200,0,8,uComps.StampCodeType.PDF417,0);
  7. canvasStampBarcode(canvas, "345 and text",220,600,0,19,uComps.StampCodeType.QR_CODE,0);
  8. }

canvasStampBuffer(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y)

canvasStampBuffer stamp a source canvas region onto the target canvas
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

int

the source top left
src_width,src_height

int

the source width and height
dst_x,dst_y

int

the destination position top left
Example
  1. registerAction('canvasStampBufferTest', '', 'canvasStampBufferTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampBufferTest(canvas, canvas2) {
  3. canvasCopyBuffer(canvas, canvas2);
  4. var pixelWidth = canvasGetWidth(canvas);
  5. var pixelHeight = canvasGetHeight(canvas);
  6. canvasStampBuffer(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0);
  7. }

canvasStampChromaKey(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y, hue, hue_mask, luminance_mask, mask_shadow, mask_light)

canvasStampChromaKey removes from the canvas_src (this process is known as a key) a specific color (or chroma). This function uses the HSV transform to calculate the hue (tint),
saturation (amount of tint) and value (brightness) - this allows us to control how much of the highlights and shadows are preserved when
a colored background is removed.
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

int

the source top left
src_width,src_height

int

the source width and height
dst_x,dst_y

int

the destination position top left
hue

real

the color converted to hue (hsv) from 0 to 360, 0 red, 90 green, 180 blue
hue_mask

real

the hue tollerance to generate the mask, 0 to 1, 0.1 or 0.06 are good values
luminance_mask

real

the amount of luminance tollerance, 0 to 5, 1.5 is a good value
mask_shadow

real

the amount of shadow preserved, 0 to 5, 2.6 is a good value, smaller means less shadow is added
mask_light

real

the amount of saturated color preserved, 0 to 5, 0.9 is a good value, more means more highlights may be picked up
Example
  1. //This operation won't show if you use the same component as source and destination.
  2. //The size of the destination needs to be big enough to fit the stamp otherwise you will only see part of it and it may not be clear it has worked.
  3. registerAction('canvasStampChromaKeyTest', '', 'canvasStampChromaKeyTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  4. function canvasStampChromaKeyTest(canvas, canvas2) {
  5. var pixelWidth = canvasGetWidth(canvas2);
  6. var pixelHeight = canvasGetHeight(canvas2);
  7. canvasResetColor(canvas, '0xFFFFFFFF'); //make bg white so we can see the result
  8. canvasStampChromaKey(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0, 90, 0.06, 1.5, 2.6, 0.9);
  9. }

canvasStampColorChannel(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y, src_channel, dst_channel)

canvasStampColorChannel stamp a source canvas region onto the target canvas from one channel to another
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

int

the source top left
src_width,src_height

int

the source width and height
dst_x,dst_y

int

the destination position top left
src_channel

int

(0 to 3) 0 Red, 1 Green, 2 Blue, 3 Alpha
dst_channel

int

(0 to 3) 0 Red, 1 Green, 2 Blue, 3 Alpha
Example
  1. registerAction('canvasStampColorChannelTest', '', 'canvasStampColorChannelTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampColorChannelTest(canvas, canvas2) {
  3. var pixelWidth = canvasGetWidth(canvas2);
  4. var pixelHeight = canvasGetHeight(canvas2);
  5. canvasStampColorChannel(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0, 1, 2);
  6. }

canvasStampCustom(canvas, canvas_src, canvas_lut, src_x, src_y, src_width,src_height, dst_x, dst_y, registers, pixel_code)

canvasStampCustom stamp a custom set of vectorised instructions onto the canvas

This is an image processing register based virtual machine. This exploits a single CPU core and is vectorised for better performance than scripting. For much better performance a VulkanCompute shader would be recommended.
There are 256 floating point registers which hold 4 channels each. For an 8 bit RGBA image this would be equivalent to 0-255 for each channel where each register is equivalent to a pixel.
The instruction buffer is composed of 8 bit instruction op codes, 8 bit register indexes, 16 bit program addresses and 32 bit floating point values.

The instruction set is as follows;

noop = 0, // no operation
samp = 1, // samp(pixel_index_from, reg) sample from 0 1 2 / 3 4 5 / 6 7 8 (source)
// 9 10 11 / 12 13 14 / 15 16 17 (destination) into register
sampgrey = 3, // sample grey(reg_to, channel_to) 9 pixels greyscale into register channel
sampavg = 4, // sample avg(reg_to) register holds r, g and b averages for 9 source pixels
sampsum = 5, // sample sum(reg_to) register holds r, g and b sum for 9 source pixels
sampmax = 6, // sample max(reg_to) register holds r, g and b maximum across the 9 source pixels
sampmin = 7, // sample min(reg_to) register holds r, g and b minimum across the 9 source pixels

copy = 8, // direct copy() from source into the destination pixel
ccopy = 9, // copy(channel_from, channel_to) from source into the destination pixel
store = 10, // store(reg) from selected register to destination all channels (RGBA)
cstore = 11, // channel store(reg, channel_from, channel_to) from register channel into the
// destination pixel channel

add = 16, // add(reg,reg_value) add reg_value into reg
addc = 17, // add constant(reg,const) add constant into reg RGB
cadd = 18, // channel add(reg,channel,reg_value,channel_value) add reg_value/channel_value
// into reg/channel
caddc = 19, // channel add constant (reg,channel,const) add constant into reg/channel

sub = 20, // sub(reg,reg_value) sub reg_value into reg
subc = 21, // sub constant(reg,const) sub constant into reg RGB
csub = 22, // channel sub(reg,channel,reg_value,channel_value) sub reg_value/channel_value
// into reg/channel
csubc = 23, // channel sub constant (reg,channel,const) sub constant into reg/channel

mul = 24, // mul(reg,reg_value) mul reg_value into reg
mulc = 25, // mul constant(reg,const) mul constant into reg RGB
cmul = 26, // channel mul(reg,channel,reg_value,channel_value) mul reg_value/channel_value
// into reg/channel
cmulc = 27, // channel mul constant (reg,channel,const) mul constant into reg/channel
div = 28, // div(reg,reg_value) div reg_value into reg
divc = 29, // div constant(reg,const) div constant into reg RGB
cdiv = 30, // channel div(reg,channel,reg_value,channel_value) div reg_value/channel_value
// into reg/channel
cdivc = 31, // channel div constant (reg,channel,const) div constant into reg/channel
sin = 32, // sin(reg, reg_value) sin(reg_value) into register
csin = 33, // channel sin(reg, channel, reg_value, channel_value) sin(reg_value/channel_value)
// into register/channel
cos = 34, // cos(reg, reg_value) cos(reg_value) into register
ccos = 35, // channel cos(reg, channel, reg_value, channel_value) cos(reg_value/channel_value)
// into register/channel
tan = 36, // tan(reg, reg_value) reg = tan(reg_value)
ctan = 37, // channel tan(reg, channel, reg_value, channel_value) tan(reg_value/channel_value)
// into register/channel
atan = 38, // atan(reg, reg_value) atan(reg_value) into register
catan = 39, // channel atan(reg, channel, reg_value, channel_value)
// atan(reg_value/channel_value) into register/channel
pow = 40, // pow(reg, reg_value, const) pow reg_value ^ const into reg (RGB)
cpow = 41, // channel pow(reg, channel, reg_value, channel_value, const) pow
// reg_value/channel_value ^ const into reg/channel (RGB)
log = 42, // log(reg, reg_value) log reg_value into reg (RGB)
clog = 43, // channel log(reg, channel, reg_value, channel_value) log reg_value/channel_value
// into reg/channel (RGB)
sqrt = 44, // sqrt(reg, reg_value) sqrt reg_value into reg (RGB)
csqrt = 45, // channel sqrt(reg, channel, reg_value, channel_value) sqrt
// reg_value/channel_value into reg/channel (RGB)
abs = 46, // abs(reg, reg_value) abs reg_value into reg (RGB)
cabs = 47, // channel abs(reg, channel, reg_value, channel_value) abs reg_value/channel_value
// into reg/channel (RGB)
clamp = 48, // clamp(reg, reg_value, min, max) clamp reg_value(min,max) into reg (RGB)
cclamp = 49, // channel clamp(reg, channel, reg_value, channel_value, min, max) clamp
// reg_value/channel_value(min,max) into reg/channel (RGB)
floor = 51, // floor(reg, reg_value) floor reg_value into reg (RGB)
cfloor = 52, // channel floor(reg, channel, reg_value, channel_value) floor
// reg_value/channel_value into reg/channel (RGB)
ceil = 53, // ceil(reg, reg_value) ceil reg_value into reg (RGB)
cceil = 54, // channel ceil(reg, channel, reg_value, channel_value) ceil
// reg_value/channel_value into reg/channel (RGB)
compd = 55, // compute distance(reg,channel, x, y) compute distance to a point from current
// pixel into reg/channel
compa = 56, // compute angle(reg,channel, x, y) compute relative angle into reg/channel (radians)
rcompd = 57, // register compute distance(reg,channel, reg_value) compute distance to a point
// from current pixel to reg_value(RG) into reg/channel
rcompa = 58, // register compute angle(reg,channel, reg_value) compute relative angle from
// current pixel to reg_value(RG) into reg/channel (radians)
uv = 59, // uv(reg) put current pixel uv (0-1) x and y ratio into register first two
// channels(rg/xy)
typeclamp = 60, // clamp(reg, reg_source) to the output type automatically (0-255 for current
// 8 bit image types)
hsv2rgb = 61, // hsv into rgb (reg, reg_value) compute rgb from reg_value into reg
rgb2hsv = 62, // rgb into hsv (reg, reg_value) compute hsv from reg_value into reg
xyz2rgb = 63, // normal map encode into color xyz into rgb (reg, reg_value) (0/127/255) to (-1/0/1)
rgb2xyz = 64, // decode normal map into vectors rgb into xyz (reg, reg_value) (-1/0/1) to (0/127/255)
load = 65, // load(reg,value) (RGB)
cload = 66, // channel load(reg,channel,value)
// alpha blended version of store
cmixa8 = 67, // channel mix(channel_dst, reg_source, channel_source) from selected register,
// using reg alpha (8 bit = 0-255), mixed with destination pixels (RGB)
mixa8 = 68, // mix(reg) from selected register, using reg alpha (8 bit = 0-255), mixed with
// destination pixels (RGB)
cmixa = 69, // channel mix(channel_dst, reg_source, channel_source) from selected register,
// using reg alpha (0-1), mixed with destination pixels (RGB)
mixa = 70, // mix(reg) from selected register, using reg alpha (0-1), mixed with destination
// pixels (RGB)
rmixa = 71, // register mix(reg1,reg2) mix two rgb registers using alphas proportion into
// destination pixels (RGB)
cmixc = 72, // channel mix constant(channel_dst,reg_source,channel_source,ratio) mix dst and
// register channels using a constant floating point ratio (0-1)
jmp = 74, // jump to address (addr)
cjeq = 75, // jump equal(reg, channel, reg2, channel, addr)
cjneq = 76, // jump not equal(reg1, channel, reg2, channel, addr)
cjlt = 77, // jump less than (reg1, channel, reg2, channel, addr)
cjgt = 78, // jump greater than (reg1, channel, reg2, channel, addr)
jeqz = 79, // jump equal zero(reg1, channel, addr)
jneqz = 80, // jump not equal zero(reg1, channel, addr)
jltz = 81, // jump less than zero(reg1, channel, addr)
jgtz = 82, // jump greater than zero(reg1, channel, addr)
jmplong = 83, // jump increment (addr_low,addr_high)
lut = 85, // lut(reg_uv) point sample from LUT image using 0-1 UV in RG channels + alpha blend
clut = 86, // channel lut(channel_dst, reg_uv, channel_src) point sample from LUT image using
// 0-1 UV in RG from and to specified channels
hlut8 = 87, // horizontal lut(reg_y,channel_y) point sample from LUT image using U = src
// RGB(0-255) and V = reg_y (0-255) + alpha blend
mixlut = 88, // blend destination with lut(reg_uv) point sample from LUT image using 0-1 UV in
// RG channels + alpha blend
mixhlut8 = 89, // blend destination with horizontal lut(reg_y,channel_y) point sample from LUT
// image using U = src RGB(0-255) and V = reg_y (0-255) + alpha blend
bezierspline = 91, // bezierspline(reg, channel, reg_packed(rgbargba), reg_value, channel_value)

halt = 255

Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
canvas_lut

component

the Look Up Table canvas (optional)
src_x

real

the source position
src_y

real

the source position
src_width,src_height

real

the size
dst_x

real

the destination position
dst_y

real

the destination position
registers

buffer

optional 256 real32 registers
pixel_code

buffer

the 8 bit opcodes to execute
Example
  1. var reg_buffer = new ArrayBuffer(4);
  2. var registers = new DataView(reg_buffer);
  3. registers.setFloat32(0, 1);
  4. var op_buffer = new ArrayBuffer(4);
  5. var pixel_code = new DataView(op_buffer);
  6. pixel_code.setFloat32(0, 1);

canvasStampHsv(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y, hue, saturation, value)

canvasStampHsv stamps the canvas_src onto the canvas as an image which has been adjusted with the HSV transform. HSV provides
control over the hue (tint), saturation (amount of tint) and value (brightness) giving control of the amount of color in the image
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

int

the source top left
src_width,src_height

int

the source width and height
dst_x,dst_y

int

the destination position top left
hue

real

0 no change, (-180 to 180), each 90 plus and minus is a change in RGB hue
saturation

real

0 no change, (-1 to 1) -1 = desaturated, 1 = saturated
value

real

0 no change, (-1 to 1) -1 = dark, 1 = bright
Example
  1. registerAction('canvasStampHsvTest', '', 'canvasStampHsvTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampHsvTest(canvas, canvas2) {
  3. var pixelWidth = canvasGetWidth(canvas2);
  4. var pixelHeight = canvasGetHeight(canvas2);
  5. canvasStampHsv(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0, 90, 0.5, 0.5);
  6. }

canvasStampImage(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y, blendmode, samplemode)

canvasStampImage combines a target image with a source image with sub pixel accuracy and different blend and sample modes.
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

real

the source top left
src_width,src_height

real

the source width and height
dst_x,dst_y

real

the destination position top left
blendmode

int

0 noblend, 1 source - See here for the full set canvasSetBrushBlendMode
samplemode

int

0 default linear, 1 nearest neighbor for hard edges images like barcodes
Example
  1. registerAction('canvasStampImageTest', '', 'canvasStampImageTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampImageTest(canvas, canvas2) {
  3. var pixelWidth = canvasGetWidth(canvas2);
  4. var pixelHeight = canvasGetHeight(canvas2);
  5. canvasStampImage(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0, 1, 1);
  6. }

canvasStampImageCenter(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y, scale_x,scale_y, angle, blendmode, samplemode)

canvasStampImage combines a target image with a centered, scaled and rotated source image with sub pixel accuracy and different blend and sample modes.
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

real

the source top left
src_width,src_height

real

the source width and height
dst_x,dst_y

real

the destination position in the center
scale_x,scale_y

real

the scale
angle

real

the angle in degrees
blendmode

int

0 noblend, 1 source - See here for the full set canvasSetBrushBlendMode
samplemode

int

0 default linear, 1 nearest neighbor for hard edges images like barcodes
Example
  1. registerAction('canvasStampImageCenterTest', '', 'canvasStampImageCenterTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampImageCenterTest(canvas, canvas2) {
  3. var pixelWidth = canvasGetWidth(canvas2);
  4. var pixelHeight = canvasGetHeight(canvas2);
  5. canvasStampImageCenter(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 200, 200, 3, 3, 45, 1, 1, true);
  6. }

canvasStampImagePerspective(canvas, canvas_src, src_p1x,src_p1y, src_p2x,src_p2y, src_p3x,src_p3y, src_p4x,src_p4y, dst_p1x,dst_p1y, dst_p2x,dst_p2y, dst_p3x,dst_p3y, dst_p4x,dst_p4y, blendmode, samplemode)

canvasStampImagePerspective combines a target image with a source image with sub pixel accuracy applying a perspective
warp with a affine transformed source quad mapping to an affine transformed destination quad using different blend and sample modes.
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_p1x,src_p1y

real

the source top left
src_p2x,src_p2y

real

the source top right
src_p3x,src_p3y

real

the source bottom right
src_p4x,src_p4y

real

the source bottom left
dst_p1x,dst_p1y

real

the destination top left
dst_p2x,dst_p2y

real

the destination top right
dst_p3x,dst_p3y

real

the destination bottom right
dst_p4x,dst_p4y

real

the destination bottom left
blendmode

int

0 noblend, 1 source - See here for the full set canvasSetBrushBlendMode
samplemode

int

0 default linear, 1 nearest neighbor for hard edges images like barcodes
Example
  1. registerAction('canvasStampImagePerspectiveTest', '', 'canvasStampImagePerspectiveTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampImagePerspectiveTest(canvas, canvas2) {
  3. var pixelWidth = canvasGetWidth(canvas2);
  4. var pixelHeight = canvasGetHeight(canvas2);
  5. canvasStampImagePerspective(canvas, canvas2, 0, 0, 300, 0, 300, 300, 0, 300, 0, 0, 300, 0, 300, 300, 0, 300);
  6. }

canvasStampImageWarp(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_p1x,dst_p1y, dst_p2x,dst_p2y, dst_p3x,dst_p3y, dst_p4x,dst_p4y, blendmode, samplemode)

canvasStampImageWarp combines a target image with a source image with sub pixel accuracy applying an affine
warp with different blend and sample modes.
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

real

the source top left
src_width,src_height

real

the source width and height
dst_p1x,dst_p1y

real

the destination top left
dst_p2x,dst_p2y

real

the destination top right
dst_p3x,dst_p3y

real

the destination bottom right
dst_p4x,dst_p4y

real

the destination bottom left
blendmode

int

0 noblend, 1 source - See here for the full set canvasSetBrushBlendMode
samplemode

int

0 default linear, 1 nearest neighbor for hard edges images like barcodes
Example
  1. registerAction('canvasStampImageWarpTest', '', 'canvasStampImageWarpTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampImageWarpTest(canvas, canvas2) {
  3. var pixelWidth = canvasGetWidth(canvas2);
  4. var pixelHeight = canvasGetHeight(canvas2);
  5. canvasStampImageWarp(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0, 200, 0, 150, 150, 40, 200);
  6. }

canvasStampKernel(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y, mode, divider, k1,k2,k3,k4,k5,k6,k7,k8,k9)

canvasStampKernel stamps the canvas_src onto the canvas using the 3x3 kernel. This is great for simple blur, edge detect and emboss effects
None (0, 0, 0, 0, 1, 0, 0, 0, 0) / 1
Average (1, 1, 1, 1, 1, 1, 1, 1, 1) / 9
Edge Vertical (-1, 0, 1, -1, 0, 1, -1, 0, 1) / 1
Edge Horizontal (-1, -1, -1, 0, 0, 0, 1, 1, 1) / 1
Sobel Horizontal (-1, 0, 1, -2, 0, 2, -1, 0, 1) / 1
lap edge ( 0, -1, 0, -1, 4, -1, 0, -1, 0 ) / 1
lap sharpen (0, -1, 0, -1, 5, -1, 0, -1, 0) / 1
emboss (-2, -1, 0, -1, 1, 1, 0, 1, 2) / 1
gaussian (1, 2, 1, 2, 4, 2, 1, 2, 1) / 16
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

int

the source top left
src_width,src_height

int

the source width and height
dst_x,dst_y

int

the destination position top left
mode

int

0 just RGB, 1 RGB copy A from source, 2 RGB copy A from source where not zero, 3 Red only, 4 Green only, 5 Blue only, 6 Alpha only
divider

real

sum all of the 3x3 kernel then divide by this value
k1,k2,k3,k4,k5,k6,k7,k8,k9

int

the three by three kernel
Example
  1. //the source and destination canvases need to be different otherwise it doesn't work.
  2. registerAction('canvasStampKernelTest', '', 'canvasStampKernelTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  3. function canvasStampKernelTest(canvas, canvas2) {
  4. var pixelWidth = canvasGetWidth(canvas2);
  5. var pixelHeight = canvasGetHeight(canvas2);
  6. canvasStampKernel(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0, 1, 2, 3);
  7. }

canvasStampLighting(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y, brightness, contrast, shadow, fill, highlight, temperature)

canvasStampLighting stamp a source canvas region onto the target canvas while applying lighting
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

int

the source top left
src_width,src_height

int

the source width and height
dst_x,dst_y

int

the destination position top left
brightness

real

(-1 to 1) -1 = black, 0 = unmodified, 1 = white
contrast

real

(-1 to 1) -1 = no contrast / grey, 0 = unmodified, 1 = high contrast
shadow

real

(-1 to 1) -1 = shadow reduced, 0 = unmodified, 1 = shadow increased
fill

real

(-1 to 1) -1 = fill light reduced, 0 = unmodified, 1 = fill light increased
highlight

real

(-1 to 1) -1 = highlights reduced / grey, 0 = unmodified, 1 = highlights increased
temperature

real

(-1 to 1) -1 = warm / red, 0 = unmodified, 1 = cool / blue
Example
  1. registerAction('canvasStampLightingTest', '', 'canvasStampLightingTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  2. function canvasStampLightingTest(canvas, canvas2) {
  3. var pixelWidth = canvasGetWidth(canvas2);
  4. var pixelHeight = canvasGetHeight(canvas2);
  5. canvasStampLighting(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5);
  6. }

canvasStampMinmaxBlend(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y, min_blend, max_blend)

canvasStampMinmaxBlend combines a target image with a source image. This is a minimum and maximum clamp in pixel brighness
where the least extreme of the two images is sampled from. It assumes both images are of the same scene but with different lighting.
This is designed to take multiple photos of the same subject and remove extremes like shadow and bright reflections.
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

int

the source top left
src_width,src_height

int

the source width and height
dst_x,dst_y

int

the destination position top left
min_blend

int

(0 to 255) if one of the pixels is < min_blend brightness then take the brightst (remove the extreme e.g. unlit shadow areas)
max_blend

int

(0 to 255) if one of the pixels is > max_blend brightness then take the darkest (remove extreme e.g. glare)
Example
  1. //this needs certain images to be able to blend. Some image pairs just takes one or the other and does not blend. apple and ofice pics work.
  2. registerAction('canvasStampMinmaxBlendTest', '', 'canvasStampMinmaxBlendTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  3. function canvasStampMinmaxBlendTest(canvas, canvas2) {
  4. var pixelWidth = canvasGetWidth(canvas2);
  5. var pixelHeight = canvasGetHeight(canvas2);
  6. canvasStampMinmaxBlend(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0, 0.2, 10, 0.5);
  7. }

canvasStampMorphological(canvas, canvas_src, src_x,src_y, src_width,src_height, dst_x,dst_y, mode, operator)

canvasStampMorphological stamps the canvas_src onto the canvas using a morphological operator. Normally these are used for binary images,
but these operators are designed to work on RGB images. These operations are designed to be stacked, bounced from one buffer to another.
For example the common open operation is dilate followed by erode. Meanwhile close is erode followed by dilate.
Parameters:
Name Type Description
canvas

component

the target canvas
canvas_src

component

the source canvas
src_x,src_y

int

the source top left
src_width,src_height

int

the source width and height
dst_x,dst_y

int

the destination position top left
mode

int

0 just RGB, 1 RGB copy A from source, 2 RGB copy A from source where not zero, 3 Red only, 4 Green only, 5 Blue only, 6 Alpha only
operator

int

0 threshold, 1 erode, 2 dilate, 3 gradient, 4 boundary, 5 hit and miss corner, 6 thinning
Example
  1. //the source and destination canvases need to be different otherwise it doesn't work.
  2. registerAction('canvasStampMorphologicalTest', '', 'canvasStampMorphologicalTest', 'component:Canvas:canvas,component:Canvas2:canvas');
  3. function canvasStampMorphologicalTest(canvas, canvas2) {
  4. var pixelWidth = canvasGetWidth(canvas2);
  5. var pixelHeight = canvasGetHeight(canvas2);
  6. canvasStampMorphological(canvas, canvas2, 0, 0, pixelWidth, pixelHeight, 0, 0, 1, 2, 128);
  7. }

canvasStampQr(canvas, code, x, y, angle, size, codelevel)

canvasStampQr creates and stamps a QRcode onto the canvas.
Parameters:
Name Type Description
canvas

component

the target canvas.
code

string

the text/numbers to encode.
x

real

the x position for the top left of where to put the QR code.
y

real

the y position for the top left of where to put the QR code.
angle

real

the angle in degrees.
size

real

size from 1-100 pixels per bar.
codelevel

int

Redundancy level, 1=low, 4=medium, 7=high.
Example
  1. registerAction('canvasStampQrTest', '', 'canvasStampQrTest', 'component:Canvas:canvas');
  2. function canvasStampQrTest(canvas) {
  3. canvasStampQr(canvas, "QRCODE", 250, 250, 0, 19, 1);
  4. }

canvasStampSvg(canvas, x, y, xratio,yratio, angle)

canvasStampSvg stamp an SVG that had been preloaded with canvasPrepareSvg onto the canvas.
Parameters:
Name Type Description
canvas

component

the target canvas.
x

real

the x position for the top left of where to put the svg.
y

real

the y position for the top left of where to put the svg.
xratio,yratio

real

the scale width and height.
angle

real

the angle in degrees.
Example
  1. registerAction('canvasStampSvgTest', '', 'canvasStampSvgTest', 'component:Canvas:canvas');
  2. function canvasStampSvgTest(canvas) {
  3. canvasStampSvg(canvas, 0, 0, 0.5, 0.5, 90);
  4. }

canvasToTexture(canvas, output_texture)

canvasToTexture sends the canvas image to the texture target on the GPU for 3D rendering. You cannot access a texture object and so cannot use canvasToTexture without using a Renderkit.
Parameters:
Name Type Description
canvas

component

the target canvas.
output_texture

int

the target texture.

canvasTranslateTransform(canvas, x, y)

canvasTranslateTransform updates the transform translation for the current path - this will be applied during canvasDrawPathFill or canvasDrawPathStroke
Parameters:
Name Type Description
canvas

component

the target canvas.
x

real

the translation in the x direction (can be negative or positive).
y

real

the translation in the y direction (can be negative or positive).
Example
  1. registerAction('canvasTranslateTransformTest', '', 'canvasTranslateTransformTest', 'component:Canvas:canvas');
  2. function canvasTranslateTransformTest(canvas) {
  3. //draw normal shape
  4. setProperty(canvas, 'stroke_style', '#FF0000FF');
  5. setProperty(canvas, 'line_width', 4);
  6. canvasBeginPath(canvas);
  7. canvasAddRoundedRect(canvas, 200, 100, 100, 100, 20);
  8. canvasDrawPathStroke(canvas);
  9. //draw translated shape
  10. setProperty(canvas, 'stroke_style', '#FF0000FF');
  11. setProperty(canvas, 'line_width', 4);
  12. canvasBeginPath(canvas);
  13. canvasTranslateTransform(canvas, 100, 100); //applies translation in pixels
  14. canvasAddRoundedRect(canvas, 200, 100, 100, 100, 20);
  15. canvasDrawPathStroke(canvas);
  16. canvasResetTransform(canvas); //removes the transform translation for future operations.
  17. }

  • Developer Home
  • Umajin Home
  • Support Home
Menu
  • Developer Home
  • Umajin Home
  • Support Home