Angular 6 - Not able to add text on canvas dynamically

后端 未结 2 2034
谎友^
谎友^ 2021-01-25 13:30

I have created canvas element. Once user add some text with the help of keyboard, on click of done button I want to add text on canvas. I did below changes

1. im

2条回答
  •  天命终不由人
    2021-01-25 14:11

    In a pure JS implementation your code works fine:

    const canvas = document.getElementById('test');
    canvas.width = canvas.height = 100;
    ctx = canvas.getContext('2d');
    ctx.font = 'italic 18px Arial';
    ctx.textAlign = 'center';
    ctx. textBaseline = 'middle';
    ctx.fillStyle = 'red';  
    ctx.fillText('Hello!', 50, 50); 
      
    

    The only issue that I could see is the:
    this.canvasElement = this.canvas.nativeElement;
    That must not be getting the correct canvas

提交回复
热议问题