Angular 6 - Not able to add text on canvas dynamically

后端 未结 2 2011
谎友^
谎友^ 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:32

    For TypeScript/Angular:

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

提交回复
热议问题