SHARE
TWEET

Untitled

a guest Jun 20th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @ViewChild('canvas') canvas: ElementRef;
  2.  
  3. mergeImages() {
  4.   var canvas: HTMLCanvasElement = this.canvas.nativeElement;
  5.   var context = canvas.getContext('2d');
  6.  
  7.   let img1 = new Image();
  8.   let img2 = new Image();
  9.  
  10.   img1.onload = function() {
  11.     canvas.width = img1.width;
  12.     canvas.height = img1.height;
  13.     img2.src = 'imgfile2.png';
  14.   };
  15.   img2.onload = function() {
  16.     context.globalAlpha = 1.0;
  17.     context.drawImage(img1, 0, 0);
  18.     context.globalAlpha = 0.5; //Remove if pngs have alpha
  19.     context.drawImage(img2, 0, 0);
  20.   };        
  21.  
  22.   img1.src = 'imgfile1.png';
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top