Class Canvas

    • Method Detail

      • createIfSupported

        public static Canvas createIfSupported()
        Return a new Canvas if supported, and null otherwise.
        Returns:
        a new Canvas if supported, and null otherwise
      • wrap

        public static Canvas wrap​(CanvasElement element)
        Wrap an existing canvas element. The element must already be attached to the document. If the element is removed from the document, you must call RootPanel.detachNow(Widget). Note: This method can return null if there is no support for canvas by the current browser.
        Parameters:
        element - the element to wrap
        Returns:
        the Canvas widget or null if canvas is not supported by the current browser.
      • isSupported

        public static boolean isSupported()
        Runtime check for whether the canvas element is supported in this browser.
        Returns:
        whether the canvas element is supported
      • getCanvasElement

        public CanvasElement getCanvasElement()
        Returns the attached Canvas Element.
        Returns:
        the Canvas Element
      • getContext

        public Context getContext​(java.lang.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 Context2d getContext2d()
        Returns a 2D rendering context. This is a convenience method, see getContext(String).
        Returns:
        a 2D canvas rendering context
      • getCoordinateSpaceHeight

        public int getCoordinateSpaceHeight()
        Gets the height of the internal canvas coordinate space.
        Returns:
        the height, in pixels
        See Also:
        setCoordinateSpaceHeight(int)
      • getCoordinateSpaceWidth

        public int getCoordinateSpaceWidth()
        Gets the width of the internal canvas coordinate space.
        Returns:
        the width, in pixels
        See Also:
        setCoordinateSpaceWidth(int)
      • setCoordinateSpaceHeight

        public void setCoordinateSpaceHeight​(int height)
        Sets the height of the internal canvas coordinate space.
        Parameters:
        height - the height, in pixels
        See Also:
        getCoordinateSpaceHeight()
      • setCoordinateSpaceWidth

        public void setCoordinateSpaceWidth​(int width)
        Sets the width of the internal canvas coordinate space.
        Parameters:
        width - the width, in pixels
        See Also:
        getCoordinateSpaceWidth()
      • toDataUrl

        public java.lang.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 java.lang.String toDataUrl​(java.lang.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.