如何防止在下次按下鼠标时擦除画布绘图?

问题描述

我在Ionic 3 Angle V5上,我无法使用返回未定义的Viewchild,所以我使用ViewChildren et获取数组的第一项(我知道是肮脏的)

    proc sgplot data= miles;
    title "Cumulative Miles Driven by Number of Individuals"
    histogram CumulativeMiles/scale= count
    fillattrs=(color=blue);
    xaxis values= (0 to 1000 by 100)
    label= "Cumulatve Miles Driven"
    yaxis values= (0 to 50000 by 10000)
    label= "Number of Individuals";
    run;

当我画一条线时,我松开按钮,然后再次绘制将删除先前的绘制

解决方法

重置2D上下文状态

设置画布大小时,2D状态将重置为默认值。这包括所有像素,这些像素均设置为默认的transparent(如果获取上下文时使用black,则设置为默认的{alpha: false}

此外,所有2D设置(例如fillStylefonttransform等)都重置为默认值。

通过ctx.save保存的任何状态也将被删除。

任何对画布widthheight属性的写入都会发生这种情况。

例如以下内容将重置画布状态。

 canvas.width = canvas.width;

在通话startDrawing中,您设置了画布widthheight,这就是在每次鼠标按下事件时都会清除画布的原因。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...