canvas常用api

canvas常用api

属性使用参数
fillStyle(填充颜色)字符串颜色值(十六进制,rbg,rbga)
strokeStyle(线条颜色)字符串颜色值(十六进制,rbg,rbga)
lineCap(线条端点样式)字符串(buzz,round和square)
lineJoin(两线条相交时的拐点样式)字符串()
lineWidth(线条的宽度)数值类型(如果是负数,NaN或者Infinity都会忽略)
shadowColor(阴影的颜色)字符串(十六进制,rbg,rbga)
shadowBulr (阴影的模糊程度)数值类型(round)
shadowoffsetX(x轴偏移的大小)数值类型()
shadowoffsetY(y轴偏移的大小)数值类型( )
font字符串(字体大小,字体样式)
方法参数
moveTo(x,y)(起始点坐标)x轴坐标,y轴坐标
lineTo(x,y)(结束点坐标)x轴坐标,y轴坐标
beginPath()(开始路径)
closePath()(闭合路径)
stroke()()
fill() ()
save(保存当前canvas的状态在 栈的最上面)
restore( 依次从堆栈的最上方弹出存储的canvas)
strokeText( 文字描边)
fillText( 依次从堆栈的最上方弹出存储的canvas)

方法

1.绘制圆

arc(x,y,radius,startAngle,endAngle)
在这里插入图片描述

conText2d.beginPath()
    conText2d.arc(1000, 500, 100, 0, Math.PI * 2) 
    conText2d.lineWidth = 10
    conText2d.strokeStyle = 'red'
    conText2d.fillStyle = '#000'
    conText2d.stroke();
    conText2d.fill()
    conText2d.closePath()

在这里插入图片描述

2.绘制矩形

方法作用
rect(x, y, width, height)绘制矩形
fillRect(x, y, width, height)填充矩形
strokeRect(x, y, width, height)描边矩形

在这里插入图片描述

conText2d.beginPath()
    conText2d.lineWidth = 10
    conText2d.strokeStyle = '#000'
    conText2d.fillStyle = 'red'
    conText2d.rect(100, 100, 100, 100)
    conText2d.stroke()
    conText2d.fill()
    conText2d.closePath()

在这里插入图片描述

3.绘制文本

在这里插入图片描述

3.1 fillText 填充文字

conText2d.beginPath()
    conText2d.fillStyle = 'red'
    conText2d.font = '24px STheiti, SimHei';
    conText2d.fillText('hello world!', 500, 100, 200);
    conText2d.fill()
    conText2d.closePath()

在这里插入图片描述

3.2 strokeText 描边文字

conText2d.beginPath()
    conText2d.strokeStyle = 'red'
    conText2d.lineWidth = 1
    conText2d.font = '50px 宋体';
    conText2d.strokeText('hello world!', 800, 100);
    conText2d.stroke()
    conText2d.closePath()

在这里插入图片描述

4.其他方法

createImageData()创建image图像数据
putImageData()绘制 imageData对象到指定位置
clearReact()清除区域
bezierCurveTo ()绘制贝塞尔曲线

drawImage()

context.drawImage(image, dx, dy);
context.drawImage(image, dx, dy, dWidth, dHeight);
context.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);

在这里插入图片描述

分成三类:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值