public class CanvasRenderingContext2D extends HtmlUnitScriptable
CanvasRenderingContext2D.org.htmlunit.corejs.javascript.ScriptableObject.DescriptorInfo, org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator, org.htmlunit.corejs.javascript.ScriptableObject.LambdaGetterFunction, org.htmlunit.corejs.javascript.ScriptableObject.LambdaSetterFunctionCONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONSTNOT_FOUND| Constructor and Description | 
|---|
| CanvasRenderingContext2D()Default constructor. | 
| CanvasRenderingContext2D(HTMLCanvasElement canvas)Constructs in association with  HTMLCanvasElement. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | arc(double x,
   double y,
   double radius,
   double startAngle,
   double endAngle,
   boolean anticlockwise)Draws an arc. | 
| void | arcTo(double x1,
     double y1,
     double x2,
     double y2,
     double radius)Draws an arc. | 
| void | beginPath()Begins the subpaths. | 
| void | bezierCurveTo(double cp1x,
             double cp1y,
             double cp2x,
             double cp2y,
             double x,
             double y)Draws a cubic Bézier curve. | 
| void | clearRect(double x,
         double y,
         double w,
         double h)Clears the specified rectangular area. | 
| static void | clip(org.htmlunit.corejs.javascript.Context context,
    org.htmlunit.corejs.javascript.Scriptable scope,
    org.htmlunit.corejs.javascript.Scriptable thisObj,
    Object[] args,
    org.htmlunit.corejs.javascript.Function function)Creates a new clipping region. | 
| void | closePath()Closes the current subpath. | 
| static ImageData | createImageData(org.htmlunit.corejs.javascript.Context context,
               org.htmlunit.corejs.javascript.Scriptable scope,
               org.htmlunit.corejs.javascript.Scriptable thisObj,
               Object[] args,
               org.htmlunit.corejs.javascript.Function function)Returns the  ImageDataobject. | 
| CanvasGradient | createLinearGradient(double x0,
                    double y0,
                    double r0,
                    double x1,
                    Object y1,
                    Object r1)Creates linear gradient. | 
| void | createPattern()Creates a pattern. | 
| CanvasGradient | createRadialGradient(double x0,
                    double y0,
                    double r0,
                    double x1,
                    double y1,
                    double r1)Creates a gradient. | 
| void | drawImage(Object image,
         int sx,
         int sy,
         Object sWidth,
         Object sHeight,
         Object dx,
         Object dy,
         Object dWidth,
         Object dHeight)Draws images onto the canvas. | 
| void | ellipse(double x,
       double y,
       double radiusX,
       double radiusY,
       double rotation,
       double startAngle,
       double endAngle,
       boolean anticlockwise)Paints the specified ellipse. | 
| void | fill()Fills the shape. | 
| void | fillRect(int x,
        int y,
        int w,
        int h)Paints the specified rectangular area. | 
| void | fillText(String text,
        double x,
        double y)Fills a given text at the given (x, y) position. | 
| HTMLCanvasElement | getCanvas()Returns the associated  HTMLCanvasElement. | 
| HtmlUnitScriptable | getFillStyle()Returns the  fillStyleproperty. | 
| double | getGlobalAlpha()Specifies the alpha (transparency) value that is applied to shapes and images
 before they are drawn onto the canvas. | 
| ImageData | getImageData(int sx,
            int sy,
            int sw,
            int sh)Returns the  ImageDataobject. | 
| double | getLineWidth()Returns the  lineWidthproperty. | 
| HtmlUnitScriptable | getStrokeStyle()Returns the  strokeStyleproperty. | 
| void | isPointInPath()Dummy placeholder. | 
| void | jsConstructor()JavaScript constructor. | 
| void | lineDash()Dummy placeholder. | 
| void | lineData()Dummy placeholder. | 
| void | lineTo(double x,
      double y)Connect the last point to the given point. | 
| TextMetrics | measureText(Object text)Calculate TextMetrics for the given text. | 
| void | moveTo(double x,
      double y)Creates a new subpath. | 
| void | putImageData(ImageData imageData,
            int dx,
            int dy,
            Object dirtyX,
            Object dirtyY,
            Object dirtyWidth,
            Object dirtyHeight)Paints data from the given ImageData object onto the canvas. | 
| void | quadraticCurveTo(double controlPointX,
                double controlPointY,
                double endPointX,
                double endPointY)Draws a quadratic Bézier curve. | 
| void | rect(double x,
    double y,
    double w,
    double h)Renders a rectangle. | 
| void | restore()Pops state stack and restore state. | 
| void | rotate(double angle)Adds a rotation to the transformation matrix. | 
| void | save()Pushes state on state stack. | 
| void | scale(Object x,
     Object y)Changes the transformation matrix to apply a scaling transformation with the given characteristics. | 
| void | setFillStyle(String fillStyle)Sets the  fillStyleproperty. | 
| void | setGlobalAlpha(double globalAlpha)Sets the  globalAlphaproperty. | 
| void | setLineDash()Dummy placeholder. | 
| void | setLineWidth(Object lineWidth)Sets the  lineWidthproperty. | 
| void | setStrokeStyle(String strokeStyle)Sets the  strokeStyleproperty. | 
| void | setTransform(double m11,
            double m12,
            double m21,
            double m22,
            double dx,
            double dy)Resets (overrides) the current transformation to the identity matrix,
 and then invokes a transformation described by the arguments of this method. | 
| void | stroke()Calculates the strokes of all the subpaths of the current path. | 
| void | strokeRect(int x,
          int y,
          int w,
          int h)Strokes the specified rectangular area. | 
| void | strokeText()Dummy placeholder. | 
| String | toDataURL(String type)Returns the Data URL. | 
| void | transform(double m11,
         double m12,
         double m21,
         double m22,
         double dx,
         double dy)Multiplies the current transformation with the matrix described by the
 arguments of this method. | 
| void | translate(int x,
         int y)Changes the transformation matrix to apply a translation transformation with the given characteristics. | 
clone, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getWindow, getWindow, getWindowFromTopCallScope, getWithPreemption, has, hasInstance, initParentScope, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setParentScope, setupPromise, setupRejectedPromiseapplyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkNotSealed, checkPropertyChangeForSlot, checkPropertyChangeForSlot, checkPropertyDefinition, checkSlotRemoval, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureScriptableObjectButNotSymbol, ensureSymbolScriptable, ensureType, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSuperProperty, getSuperProperty, getSuperProperty, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putOwnProperty, putOwnProperty, putOwnProperty, putProperty, putProperty, putProperty, putSuperProperty, putSuperProperty, putSuperProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, sizecreateSlotMappublic CanvasRenderingContext2D()
public CanvasRenderingContext2D(HTMLCanvasElement canvas)
HTMLCanvasElement.canvas - the HTMLCanvasElementpublic void jsConstructor()
public double getGlobalAlpha()
globalAlpha propertypublic void setGlobalAlpha(double globalAlpha)
globalAlpha property.globalAlpha - the globalAlpha propertypublic HtmlUnitScriptable getFillStyle()
fillStyle property.fillStyle propertypublic void setFillStyle(String fillStyle)
fillStyle property.fillStyle - the fillStyle propertypublic HtmlUnitScriptable getStrokeStyle()
strokeStyle property.strokeStyle propertypublic void setStrokeStyle(String strokeStyle)
strokeStyle property.strokeStyle - the strokeStyle propertypublic double getLineWidth()
lineWidth property.lineWidth propertypublic void setLineWidth(Object lineWidth)
lineWidth property.lineWidth - the lineWidth propertypublic void arc(double x,
                double y,
                double radius,
                double startAngle,
                double endAngle,
                boolean anticlockwise)
x - the xy - the yradius - the radiusstartAngle - the start angleendAngle - the end angleanticlockwise - is anti-clockwisepublic void arcTo(double x1,
                  double y1,
                  double x2,
                  double y2,
                  double radius)
x1 - the x1y1 - the y1x2 - the x2y2 - the y2radius - the radiuspublic void beginPath()
public void bezierCurveTo(double cp1x,
                          double cp1y,
                          double cp2x,
                          double cp2y,
                          double x,
                          double y)
cp1x - the cp1xcp1y - the cp1ycp2x - the cp2xcp2y - the cp2yx - the xy - the ypublic void clearRect(double x,
                      double y,
                      double w,
                      double h)
x - the xy - the yw - the widthh - the heightpublic static void clip(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function)
context - the JavaScript contextscope - the scopethisObj - the scriptableargs - the arguments passed into the methodfunction - the functionpublic void closePath()
public static ImageData createImageData(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function)
ImageData object.
 this may accept a variable number of arguments.context - the JavaScript contextscope - the scopethisObj - the scriptableargs - the arguments passed into the methodfunction - the functionImageData objectpublic CanvasGradient createLinearGradient(double x0, double y0, double r0, double x1, Object y1, Object r1)
x0 - the x0y0 - the y0r0 - the r0x1 - the x1y1 - the y1r1 - the r1public void createPattern()
public CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1)
x0 - the x axis of the coordinate of the start circley0 - the y axis of the coordinate of the start circler0 - the radius of the start circlex1 - the x axis of the coordinate of the end circley1 - the y axis of the coordinate of the end circler1 - the radius of the end circlepublic void drawImage(Object image, int sx, int sy, Object sWidth, Object sHeight, Object dx, Object dy, Object dWidth, Object dHeight)
image - an element to draw into the contextsx - the X coordinate of the top left corner of the sub-rectangle of the source image
        to draw into the destination contextsy - the Y coordinate of the top left corner of the sub-rectangle of the source image
        to draw into the destination contextsWidth - the width of the sub-rectangle of the source image to draw into the destination contextsHeight - the height of the sub-rectangle of the source image to draw into the destination contextdx - the X coordinate in the destination canvas at which to place the top-left corner of the source imagedy - the Y coordinate in the destination canvas at which to place the top-left corner of the source imagedWidth - the width to draw the image in the destination canvas. This allows scaling of the drawn imagedHeight - the height to draw the image in the destination canvas. This allows scaling of the drawn imagepublic String toDataURL(String type)
type - an optional typepublic void ellipse(double x,
                    double y,
                    double radiusX,
                    double radiusY,
                    double rotation,
                    double startAngle,
                    double endAngle,
                    boolean anticlockwise)
x - the xy - the yradiusX - the radiusXradiusY - the radiusYrotation - the rotationstartAngle - the startAngleendAngle - the endAngleanticlockwise - the anticlockwisepublic void fill()
public void fillRect(int x,
                     int y,
                     int w,
                     int h)
x - the xy - the yw - the widthh - the heightpublic void fillText(String text, double x, double y)
text - the textx - the xy - the ypublic ImageData getImageData(int sx, int sy, int sw, int sh)
ImageData object.sx - xsy - ysw - widthsh - heightImageData objectpublic void lineDash()
public void lineData()
public void isPointInPath()
public void lineTo(double x,
                   double y)
x - the xy - the ypublic TextMetrics measureText(Object text)
text - the text to measurepublic void moveTo(double x,
                   double y)
x - the xy - the ypublic void putImageData(ImageData imageData, int dx, int dy, Object dirtyX, Object dirtyY, Object dirtyWidth, Object dirtyHeight)
imageData - an ImageData object containing the array of pixel valuesdx - horizontal position (x coordinate) at which to place the image data in the destination canvasdy - vertical position (y coordinate) at which to place the image data in the destination canvasdirtyX - horizontal position (x coordinate) of the top-left corner
        from which the image data will be extracted. Defaults to 0.dirtyY - vertical position (y coordinate) of the top-left corner
        from which the image data will be extracted. Defaults to 0.dirtyWidth - width of the rectangle to be painted.
        Defaults to the width of the image data.dirtyHeight - height of the rectangle to be painted.
        Defaults to the height of the image data.public void quadraticCurveTo(double controlPointX,
                             double controlPointY,
                             double endPointX,
                             double endPointY)
controlPointX - the x-coordinate of the control pointcontrolPointY - the y-coordinate of the control pointendPointX - the x-coordinate of the end pointendPointY - the y-coordinate of the end pointpublic void rect(double x,
                 double y,
                 double w,
                 double h)
x - the xy - the yw - the widthh - the heightpublic void restore()
public void rotate(double angle)
angle - the anglepublic void save()
public void scale(Object x, Object y)
x - the scale factor in the horizontal directiony - the scale factor in the vertical directionpublic void setLineDash()
public void setTransform(double m11,
                         double m12,
                         double m21,
                         double m22,
                         double dx,
                         double dy)
m11 - Horizontal scaling. A value of 1 results in no scalingm12 - Vertical skewingm21 - Horizontal skewingm22 - Vertical scaling. A value of 1 results in no scalingdx - Horizontal translation (moving)dy - Vertical translation (moving).public void stroke()
public void strokeRect(int x,
                       int y,
                       int w,
                       int h)
x - the xy - the yw - the widthh - the heightpublic void strokeText()
public void transform(double m11,
                      double m12,
                      double m21,
                      double m22,
                      double dx,
                      double dy)
m11 - Horizontal scaling. A value of 1 results in no scalingm12 - Vertical skewingm21 - Horizontal skewingm22 - Vertical scaling. A value of 1 results in no scalingdx - Horizontal translation (moving)dy - Vertical translation (moving).public void translate(int x,
                      int y)
x - the translation distance in the horizontal directiony - the translation distance in the vertical directionpublic HTMLCanvasElement getCanvas()
HTMLCanvasElement.HTMLCanvasElementCopyright © 2002–2025 Gargoyle Software Inc.. All rights reserved.