[F/OS] CanvasLayers - powerful tools for the Canvas component

:man_running: CanvasLayers

A comprehensive multi-layer canvas extension for MIT App Inventor 2 with drawing, selection, effects, and export tools.

:memo: Specifications

:package: Package com.iagolirapassos.canvaslayers
:floppy_disk: Size 84.94 KB
:gear: Version 1.4
:iphone: Minimum API 14
:date: Updated 2026-02-17
:computer: Built with FAST v5.5.0

:clipboard: Overview

CanvasLayers is a powerful extension that transforms your Canvas component into a professional-grade layer-based drawing application. It consists of 5 integrated components that work together seamlessly:

Component Description
CanvasLayers Core layer management and effects
CanvasExportTools Image and PDF export functionality
CanvasEffectsTools Filters and visual effects
CanvasDrawingTools Shape creation and manipulation
CanvasPickerTools Dialogs and layer picker interface

:wrench: Initial Setup

Before using any tools, you MUST initialize all components:

When Screen1.Initialize
  // 1. Configure main extension
  call CanvasLayers1.SetCanvas(Canvas1)
  call CanvasLayers1.AddLayer("Background", true, -1)
  
  // 2. Initialize all tools with the main extension
  call CanvasDrawingTools1.Initialize(CanvasLayers1)
  call CanvasSelectionTools1.Initialize(CanvasLayers1)
  call CanvasEffectsTools1.Initialize(CanvasLayers1)
  call CanvasExportTools1.Initialize(CanvasLayers1)
  call CanvasPickerTools1.Initialize(CanvasLayers1)
  
  // 3. Connect drawing tools for real-time preview
  call CanvasLayers1.SetDrawingTools(CanvasDrawingTools1)

:jigsaw: Component Details

CanvasLayers – Core Component

The heart of the extension that manages layers, undo/redo stacks, and basic operations.

:pushpin: Properties

Getter Type Description
CanvasWidth number Current canvas width
CanvasHeight number Current canvas height
NumberOfLayers number Total layers count
GetActiveLayerName text Name of active layer
GetIsSelection boolean Rectangular selection active
GetIsFreeSelection boolean Freeform selection active
GetAnchorComponent component Layer picker anchor
Setter Type Description
CanvasWidth number Set canvas width
CanvasHeight number Set canvas height
OffsetX number Set drawing X offset
OffsetY number Set drawing Y offset

:dart: Key Methods

Method Description
AddLayer(name, alpha, color) Create new layer
RemoveLayer() Delete active layer
ClearMemory() Free up bitmap resources
MergeDown() Merge active layer with layer below
DuplicateLayer(source, newName) Clone existing layer
MoveLayerToIndex(name, index) Reorder layers
InvertLayerColors(name) Color inversion effect
SetLayerOpacity(name, 0-255) Transparency control
ApplySepia(name) Sepia filter
FlipLayerHorizontal/Vertical(name) Mirror layer
RotateLayer90(name) 90° rotation

:zap: Events

Event Parameters Description
OnError functionName, errorMessage Error occurred
ReportError errorMessage Custom error
OnNoLayers No layers remain
CanvasSizeChanged width, height Canvas resized
OnMemoryCleared Memory freed

CanvasExportTools – Export Component

Save your work as images or PDF documents.

:outbox_tray: Export Methods

Method Description
SaveLayersToImage(name, type, dir) Save all visible layers
SaveLayerToImage(layer, name, type, dir) Save specific layer
SaveLayersToSeparatePDFPages(file, dir) Multi-page PDF
SaveAllLayersToOnePDFPage(file, dir) Single-page PDF

ImageType options: Png, Jpeg, Webp

:loudspeaker: Events

Event Parameters Description
LayerSaved filePath Export completed

CanvasEffectsTools – Effects Component

Apply filters and transformations to your layers.

:art: Effect Methods

Method Description
ZoomIn/OutActiveLayer(factor) Scale layer
ZoomIn/OutAtPoint(x, y, factor) Zoom at specific point
AdjustBrightness(layer, factor) Brightness control
ConvertToPixelArt() Pixelate active layer
ResizeLayer(layer, width, height) Resize layer
ConvertLayerToGrayscale(layer) Black & white
ApplyBlurToLayer(layer, radius) Gaussian blur
ApplyBlurToSelectedArea(radius) Blur selection only
CombineLayers(layer1, layer2, type) Merge with blend mode

CanvasDrawingTools – Drawing Component

Create, manipulate, and select shapes with real-time preview.

:paintbrush: Shape Creation

Method Description
StartShape(type, x, y, color, width, filled) Begin shape
StartTextAtPoint(x, y, text, color, size) Create text
UpdateShape(x, y) Resize during drag
DrawShape() Finalize and draw
CancelShape() Abort creation
AddPointToPolygon(x, y) Add polygon vertex

ShapeType options: Rectangle, RoundRect, Oval, Line, Arrow, Polygon, Star, Text, Image, FreePath

:sparkles: Special Effects

Method Description
DrawLinearGradient(l, t, r, b, start, end, horiz) Gradient rectangle
DrawRadialGradient(cx, cy, r, center, edge) Gradient circle
DrawGlow(cx, cy, r, color, alpha) Glow effect
AddImageToActiveLayer(path) Import image

:dart: Selection Tools

Method Description
StartSelection(x, y) Begin rectangular selection
StartFreeformSelection(x, y) Begin freehand selection
UpdateSelection(x, y) Adjust during drag
EndSelection(type) Complete selection
ClearSelection() Hide selection box
SelectAll() Select entire layer
CopySelectedArea() Copy rectangular area
CutSelectedArea() Cut rectangular area
CopyFreeSelectedArea() Copy freeform area
CutFreeSelectedArea() Cut freeform area
PasteCopiedArea() Paste at last position
PasteCopiedAreaAtPoint(x, y) Paste at specific point

SelectionType options: Rectangle, Free, All, None

:package: Basic Drawing

Method Description
DrawPixelOnActiveLayer(x, y, color, size) Square pixel
DrawPointOnActiveLayer(x, y, color, size) Circular point
DrawLineOnActiveLayer(x1,y1,x2,y2,color,width) Line
DrawWithBrushTexture(texturePath, size) Pattern brush
DrawWithShinyBrush(color, size) Glossy brush
Erase(x, y, radius) Eraser tool
FloodFill(x, y, color, tolerance) Fill area

:straight_ruler: Line & Arrow Tools

Method Description
StartLine(x, y, color, width) Begin line
UpdateLine(x, y) Adjust endpoint
DrawLine() Finalize line
StartArrow(x, y, color, width) Begin arrow
UpdateArrow(x, y) Adjust endpoint
DrawArrow() Finalize arrow

:black_square_button: Grid System

Method Description
DrawGrid(hSpacing, vSpacing) Show grid overlay
RemoveGrid() Hide grid

CanvasPickerTools – UI Component

Dialog and picker interfaces for layer management.

:control_knobs: Layer Picker

Method Description
SetAnchorComponent(comp, thumbColor, size, bgColor, textColor, divider) Configure picker
ShowLayerPicker() Display layer list
ShowLayerPickerWithDelay() Show after short delay

:speech_balloon: Dialog Methods

Method Description
ShowAlertDialog(title, message, bgColor, showCancel, showOk) Simple alert
ShowLayerSelectionDialog(title, bgColor, textColor, spinnerBg, showCancel, showOk, type) Two-layer selector
ShowTextInputDialog(title, message, textColor, editBg, dialogBg, hint, default, fullScreen, showCancel, showOk, type) Text input
ShowListDialog(title, items, textColor, itemBg, dialogBg, fullScreen, showCancel, type) List selection

:art: Visual Effects

Method Description
RoundCorners(comp, radius, bg, border, width, childBg, text, applyToChildren, applyToGroups) Rounded corners
RoundCornersMetallic(comp, radius, baseColor, childBg, text, applyToChildren, applyToGroups) Metallic effect

:loudspeaker: Picker Events

Event Parameters Description
OnLayerSelected layerName Layer chosen
OnLayerLongPressed layerName Long press on layer
OnOutsidePicker Clicked outside
TextEntered text, type Dialog input
ListItemSelected item, type List choice
LayersSelected layer1, layer2, type Two layers chosen

:books: Example Projects

Simple Drawing App

When Screen1.Initialize
  // Setup
  call CanvasLayers1.SetCanvas(Canvas1)
  call CanvasLayers1.AddLayer("Sketch", true, -1)
  call CanvasDrawingTools1.Initialize(CanvasLayers1)
  call CanvasLayers1.SetDrawingTools(CanvasDrawingTools1)
  
When Canvas1.TouchDown
  x y
  call CanvasDrawingTools1.StartPathAtPoint(x, y, -16776961, 5)
  
When Canvas1.TouchMove
  x y
  call CanvasDrawingTools1.AddPointToPath(x, y)
  
When Canvas1.TouchUp
  x y
  call CanvasDrawingTools1.DrawShape()

Layer Management

When ButtonAdd.Click
  call CanvasLayers1.AddLayer("New Layer", true, -1)
  
When ButtonDelete.Click
  if call CanvasLayers1.NumberOfLayers() > 1
    call CanvasLayers1.RemoveLayer()
  else
    call Notifier1.ShowAlert("Can't remove last layer")
  
When Spinner1.AfterSelecting
  selection
  call CanvasLayers1.SetActiveLayer(selection)

Export to Image

When ButtonSave.Click
  call CanvasExportTools1.SaveLayersToImage(
    "my_drawing",
    "png",
    "MyApp"
  )
  
When CanvasExportTools1.LayerSaved
  path
  call Notifier1.ShowAlert("Saved to: " + path)

:package: Helper Enums

Enum Values
ImageType Png, Jpeg, Webp
ShapeType Rectangle, RoundRect, Oval, Line, Arrow, Polygon, Star, Text, Image, FreePath
SelectionType Rectangle, Free, All, None

:link: Links

Files

AIX: (V3) com.iagolirapassos.canvaslayers.aix (84.9 KB)
AIA: (V3) CanvasLayers.aia (656.2 KB)


Made with ❤️ for the MIT App Inventor community





5 Likes

It would be nicer if you present your blocks in a different way with images. An average user isnt aware of such technical things, AndroidViewComponent.

Suggestion: It would be nice if the platform offered a security mechanism for AIA and AIX files.

Is there anything else left for the post to be published?

I think, we can publish it...
this is a nice to have...

Taifun

2 Likes

NEWS

AIX has been released completely free. Private support will be provided for a payment of $5.00.

Wait for version 2!

hi,
Can you say to me your contack number ?
Thanks

1 Like

Telegram group Telegram: Contact @mitappinvnetorandbrothers

its possible to make blur effect zoom with this?

1 Like

you need to get the width and height of the image, and set the canvas with same ratio.

@TIMAI2 The project is now open source, in case you want to contribute to or modify the original project.

OK that is good. I wanted a clearMemory method which is in the legacy version "ExtendedCanvas".

Can you share the source code java for that ?

1 Like

New upgrade

components