1

I want to write on the image using canvas but when I zoom the image mouse pointer change and it does not write in the correct place

kindly help me where I need to change that code Thanks in advance

Syed Ali Shahzil
  • 1,079
  • 1
  • 11
  • 17

1 Answers1

1

One way you can do is that calculate the scale how much it increases with zoom in and then multiple your x and y coordinate with that scale

 var rect = canvas.getBoundingClientRect();  // abs. size of element
 scaleX = canvas.width / rect.width;  // relationship bitmap vs. element for X
 scaleY = canvas.height / rect.height; // relationship bitmap vs. element for Y
 mouseX = mouseX*scaleX;
 mouseY = mouseY*scaleY;
Syed Ali Shahzil
  • 1,079
  • 1
  • 11
  • 17