1.context
var context = canvas.getContext('2d');
2.Canvas state
context.save();
context.restore();
3.Line styles
context.lineWith[= value];
context.lineCap[= value];
context.lineJoin[= value];
context.miterLimit[= value];
context.setLineDash([5, 25]);
context.getLineDash();
context.lineDashOffset();
3.Text styles
context.font[= value];
context.textAlign[= value];
context.textBaseLine[= value];
3.Building Path
context.moveTo(x,y)
context.closePath()
context.lineTo(x,y)
context.quadraticCurveTo(cpx,cpy,x,y)
context.bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y)
context.arcTo(x1,y1,x2,y2,radius)
context.arc(x,y,radius,startAngle,endAngle)
context.rect(x,y,w,h)
3.Transformations
context.scale(x,y)
context.rotate(angle)
context.translate(x,y)
context.transform(a,b,c,d,e,f)
context.setTransform(a,b,c,d,e,f);
3.Fill and stroke styles
context.fillStyle[= value];
context.strokeStyle[= value];
var gradient = context.creatLinearGradient(x0,y0,x1,y1)
var gradient = context.creatRadialGradient(x0,y0,x1,y1)
gradient.addColorStop(offset,color);
var pattern = context.createPattern(image,repetition);
3.Drawing rectangles to the canvas
context.clearRect(x,y,w,h);
context.fillRect(x,y,w,h);
context.strokeRect(x,y,w,h);
3.Drawing text to the canvas
context.fillText(text,x,y,[,maxWidth]);
context.strokeText(text,x,y,[,maxWidth]);
var metrics = context.measureText(text);
metrics.width;
3.Drawing paths to the canvas
context.beginPath();
context.fill();
context.stroke();
context.drawFocusIfNeed(element);
context.clip();
context.isPoingInPath(x,y);
3.Dawing images to the canvas
context.drawImage(image,dx,dy);
context.drawImage(image,dx,dy,dw,dh);
context.drawImage(image,sx,sy,sw,sh,dx,dy,dw,dh);
image 的值为 HTMLImageElement,HTMLCanvasElement,HTMLVideoElement