0
votes

I'm using canvas and I think the default width, and height size 300px/150px. I want to customize the width, I use Angular.

I did try to put canvas { width:400px } in app.component.css but didn't work

app.component.ts

        convertURIToImageData=> (url) => {
         return new Promise((resolve, reject) => {
         if (!url) {
             return reject();
           }
   const canvas = document.createElement('canvas');
   const context = canvas.getContext('2d');
   context.font = '30px Arial';
   context.fillText('Hello World', 10, 50);
   const image = new Image();
   image.addEventListener('load', function() {
          canvas.width = image.width;
          canvas.height = image.height;
          context.drawImage(image, 0, 0, canvas.width, 
          canvas.height);
          resolve(context.getImageData(0, 0, 
          canvas.width, canvas.height));
          image.crossOrigin = 'Anonymous';
          image.src = url;
                   });
             });
           };