Creating Surfaces
Surface Methods
Returns the canvas for drawing on the surface
Captures the surface content as an image. Optionally specify a rectangle to capture only a portion.
Ensures all queued draw operations are completed
Returns the width of the surface
Returns the height of the surface
Use Cases
Caching Complex Renders
Pre-render complex graphics for better performance:Generating Textures
Create procedural textures:Image Processing
Manipulate images:Creating Thumbnails
Generate smaller versions of images:Compositing Multiple Images
Drawing on Canvas
The canvas obtained from a surface has all standard drawing methods:Saving Surface Output
Performance Considerations
- Surfaces allocate memory for offscreen buffers - use judiciously
- Larger surfaces use more memory
- Create surfaces once and reuse when possible
- Call
flush()to ensure rendering is complete before capturing - Dispose of surfaces when no longer needed (automatic in JavaScript)
- For repeated renders, consider caching the result as an image