Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2012 Google Inc.
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
package elemental.html;
import  elemental.html.*;
DOM canvas elements expose the HTMLCanvasElement interface, which provides properties and methods for manipulating the layout and presentation of canvas elements. The HTMLCanvasElement interface inherits the properties and methods of the element object interface.
public interface CanvasElement extends Element {

Reflects the height HTML attribute, specifying the height of the coordinate space in CSS pixels.
  int getHeight();
  void setHeight(int arg);

Reflects the width HTML attribute, specifying the width of the coordinate space in CSS pixels.
  int getWidth();
  void setWidth(int arg);

Returns a drawing context on the canvas, or null if the context ID is not supported. A drawing context lets you draw on the canvas. The currently accepted values are "2d" and "experimental-webgl". The "experimental-webgl" context is only available on browsers that implement WebGL. Calling getContext with "2d" returns a CanvasRenderingContext2D Object, whereas calling it with "experimental-webgl" returns a WebGLRenderingContext Object.

Returns a data: URL containing a representation of the image in the format specified by type (defaults to PNG).

  • If the height or width of the canvas is 0, "data:," representing the empty string, is returned.
  • If the type requested is not image/png, and the returned value starts with data:image/png, then the requested type is not supported.
  • Chrome supports the image/webp type.
  • If the requested type is image/jpeg or image/webp, then the second argument, if it is between 0.0 and 1.0, is treated as indicating image quality; if the second argument is anything else, the default value for image quality is used. Other arguments are ignored.
New to GrepCode? Check out our FAQ X