Class Canvas

  • All Implemented Interfaces:
    IsJSType, IsCastable

    @JsType(isNative=true,
            name="HTMLCanvasElement",
            namespace="<global>")
    public final class Canvas
    extends BaseHtmlElement
    implements IsCastable
    Represents a DOM element that enables drawing graphics and animations with own the canvas scripting API.
    Author:
    Andrea "Stock" Stocchero
    • Method Detail

      • getHeight

        @JsProperty
        public int getHeight()
        Returns a positive integer reflecting the height HTML attribute of the canvas element interpreted in CSS pixels.
        When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of 150 is used.
        Returns:
        a positive integer reflecting the height HTML attribute of the canvas element interpreted in CSS pixels
      • setHeight

        @JsProperty
        public void setHeight​(int height)
        Sets a positive integer reflecting the height HTML attribute of the canvas element interpreted in CSS pixels.
        When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of 150 is used.
        Parameters:
        height - a positive integer reflecting the height HTML attribute of the canvas element interpreted in CSS pixels
      • getWidth

        @JsProperty
        public int getWidth()
        Returns a positive integer reflecting the width HTML attribute of the canvas element interpreted in CSS pixels.
        When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of 300 is used.
        Returns:
        a positive integer reflecting the width HTML attribute of the canvas element interpreted in CSS pixels
      • setWidth

        @JsProperty
        public void setWidth​(int width)
        Sets a positive integer reflecting the width HTML attribute of the canvas element interpreted in CSS pixels.
        When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of 300 is used.
        Parameters:
        width - a positive integer reflecting the width HTML attribute of the canvas element interpreted in CSS pixels
      • getContext2d

        @JsOverlay
        public final Context2dItem getContext2d()
        Returns a drawing 2D context on the canvas.
        Returns:
        a drawing 2D context on the canvas
      • isSupported

        @JsOverlay
        public final boolean isSupported()
        Returns true if canvas is supported by browser, otherwise false.
        Returns:
        true if canvas is supported by browser, otherwise false
      • toDataURL

        @JsOverlay
        public final String toDataURL()
        Returns a data-URL containing a representation of the image in the PNG format and the image quality value is 0.92.
        Returns:
        a data-URL containing a representation of the image in the PNG format
      • toDataURL

        @JsOverlay
        public final String toDataURL​(double encoderOptions)
        Returns a data-URL containing a representation of the image in the PNG format.
        The returned image is in a resolution of 96dpi.
        Parameters:
        encoderOptions - between 0 and 1 indicating the image quality to use for image formats that use lossy compression.
        If this argument is anything else, the default value for image quality is used. The default value is 0.92.
        Returns:
        a data-URL containing a representation of the image in the PNG format
      • toDataURL

        @JsOverlay
        public final String toDataURL​(ImageMimeType type)
        Returns a data-URL containing a representation of the image format, passed as argument.
        The returned image is in a resolution of 96dpi and the image quality value is 0.92.
        Parameters:
        type - indicating the image format
        Returns:
        a data-URL containing a representation of the image format, passed as argument
      • toDataURL

        @JsOverlay
        public final String toDataURL​(ImageMimeType type,
                                      double encoderOptions)
        Returns a data-URL containing a representation of the image format, passed as argument.
        The returned image is in a resolution of 96dpi.
        Parameters:
        type - indicating the image format
        encoderOptions - between 0 and 1 indicating the image quality to use for image formats that use lossy compression.
        If this argument is anything else, the default value for image quality is used. The default value is 0.92.
        Returns:
        a data-URL containing a representation of the image format, passed as argument