Understanding Zoom Using Canvas' setTransform

Asked 2 years ago, Updated 2 years ago, 35 views

I am currently using JavaScript to create drawing software.
So I want to create a zoom function, but it doesn't work.
Below is the code

 function zoom(x,y)
{
    varcanvas= document.getElementById('canvas');
    varctx = canvas.getContext('2d');
    var width = canvas.width;
    var height = canvas.height;

    var ImageData=ctx.getImageData(0,0, width, height);

    ctx.setTransform(x,0,0,y,0,0);

    ctx.putImageData(ImageData,0,0);
}

I changed the zoom function x and y arbitrarily, but it doesn't work.
After changing the magnification, I pasted the image using drawImage and found the magnification specified.
Can't I use getImageData or putImageData?
There are many ways to change the magnification, but I would like to use setTransform for future production.

Why can't I do it well?

If you understand, please give us some advice or suggestions.

javascript html

2022-09-29 22:56

1 Answers

Instead of using the canvas context setTransform.
I increased the size of the canvas itself using transform of css.
I was able to do this by setting the overflow:hidden in

by setting the range of view.

I used this as a reference.
http://am-yu.net/2014/04/13/canvas-pbbs-expansion/


2022-09-29 22:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.