UBCanvas

@unitybase/canvas~ UBCanvas

new UBCanvas(width, height, fillColoropt)

Create new Canvas and fill it by provided color.
Arguments:
  1. width (Number)
  2. height (Number)
  3. [fillColor=0] (Number|Object)  Either a result of UBCanvas#createColor or object {r: Number, g: number, b: Number}

Members

FontStyles: Object static

Possible font style for setFont

TextFormats: Object static

Possible text drawing options for drawText

Methods

createNew(width, height, fillColoropt)

Set Canvas width and height in pixels & fill it by provided color. In case color is 0 or omitted, fill with white.

It is mandatory to call createNew before any other Canvas operation.

Arguments:
  1. width (Number)
  2. height (Number)
  3. [fillColor=0] (Number|Object)  Either a result of UBCanvas#createColor or object {r: Number, g: number, b: Number}

setFont(fontName, fontColor, fontSize, fontStylesopt)

Set a font for future UBCanvas#drawText operations
Arguments:
  1. fontName (String)  Name of font as it displayed in the OS
  2. fontColor (Number|Object)  Either a result of UBCanvas#createColor or object {r: Number, g: number, b: Number}
  3. fontSize (Number)  Font size in punkts
  4. [fontStyles] (Array.<{UBCanvas.FontStyle}>)  Default is []

drawText(x, y, text, clipWidth, clipHeight, drawOptionsopt)

Draw a text on the Canvas using previously defined Font
Arguments:
  1. x (Number)
  2. y (Number)
  3. text (String)
  4. clipWidth (Number)
  5. clipHeight (Number)
  6. [drawOptions] (Array.<{UBCanvas.TextFormat}>)  return {{width: Number, height: Number}} text rectangle

measureText(text)Object

Arguments:
  1. text (String)

drawImage(x, y, image, widthopt, heightopt, imageTypeopt)

Arguments:
  1. x (Number)
  2. y (Number)
  3. image (ArrayBuffer)
  4. [width=0] (Number)  0 - image width or calculated proportionally
  5. [height=0] (Number)  0 - image height or calculated proportionally
  6. [imageType=UBCanvas.imageTypes.PNG] (Number)  UBCanvas.imageTypes (0 - BMP, 1 - PNG, 2 - JPEG, 3 - GIF)

saveToFile(fileName)

Save Canvas content to file in PNG format
Arguments:
  1. fileName (String)

getContent()

Get Canvas content. See UBReader#read

freeNative()

Release all internal resources. Do not use this object after call to freeNative!