Class CanvasElement


@TagName("canvas") public class CanvasElement extends Element
Canvas element.
See Also:
  • Field Details

  • Constructor Details

    • CanvasElement

      protected CanvasElement()
  • Method Details

    • getContext

      public final Context getContext(String contextId)
      Gets the rendering context that may be used to draw on this canvas.
      Parameters:
      contextId - the context id as a String
      Returns:
      the canvas rendering context
    • getContext2d

      public final Context2d getContext2d()
      Returns a 2D rendering context. This is a convenience method, see getContext(String).
      Returns:
      a 2D canvas rendering context
    • getHeight

      public final int getHeight()
      Gets the height of the canvas.
      Returns:
      the height, in pixels
      See Also:
    • getWidth

      public final int getWidth()
      Gets the width of the canvas.
      Returns:
      the width, in pixels
      See Also:
    • setHeight

      public final void setHeight(int height)
      Sets the height of the canvas.
      Parameters:
      height - the height, in pixels
      See Also:
    • setWidth

      public final void setWidth(int width)
      Sets the width of the canvas.
      Parameters:
      width - the width, in pixels
      See Also:
    • toDataUrl

      public final String toDataUrl()
      Returns a data URL for the current content of the canvas element.
      Returns:
      a data URL for the current content of this element.
    • toDataUrl

      public final String toDataUrl(String type)
      Returns a data URL for the current content of the canvas element, with a specified type.
      Parameters:
      type - the type of the data url, e.g., image/jpeg or image/png.
      Returns:
      a data URL for the current content of this element with the specified type.