//填充画布,五位随机数
    drawNumber(): void {
        this.clearCanvas();

        let ctx: CanvasRenderingContext2D = this.myGraph.nativeElement.getContext("2d");

        ctx.shadowBlur = 200;
        ctx.shadowColor = "black";
        ctx.font = "italic 20px Verdana";
        ctx.textAlign = "left";

        var gradient = ctx.createLinearGradient(0, 0, this.myGraph.nativeElement.width, 0);
        gradient.addColorStop(0, "magenta");
        gradient.addColorStop(0.5, "blue");
        gradient.addColorStop(1.0, "red");

        ctx.strokeStyle = gradient;

 var num = Math.random().toFixed(5) + "";
 this.validateCode = num.slice(2)
 ctx.strokeText(this.validateCode, 3, 22);

}

清空画布
    clearCanvas(): void {
        let ctx: CanvasRenderingContext2D = this.myGraph.nativeElement.getContext("2d");
        ctx.clearRect(0, 0, this.myGraph.nativeElement.width, this.myGraph.nativeElement.height);
    }

 

相关文章:

  • 2021-08-17
  • 2021-08-06
  • 2022-12-23
  • 2021-07-22
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-08-24
  • 2021-12-25
相关资源
相似解决方案