HTMl5里新元素很多,但画布<canvas>绝对是大人气,本篇要简介下画布<canvas>,并亲手用画布绘出验证码。
使用画布<canvas>需要先获取2D上下文:getContext("2d")
2D上下文最基本的操作就是描边和填充,分别取决于两个属性:strokeStyle,fillStyle
下面是常用的画布API:
画矩形:fillRect,strokeRect,clearRect
路径:beginPath,closePath,arc(弧度),arcTo,bezierCurveTo(曲线),quadraticCurveTo(二次曲线),moveTo,lineTo,rect。路径完成后可以用fill填充,可以用stroke描边
画文本:fillText,strokeText,textBaseline(文本基线)