why image is not center in canvas using in angularjs?

2808 views javascript
7

could you please tell me why my image is not in centered I used this method

function drawImage() {
                    clear();
                    element.save();
                    element.scale(currentScale, currentScale);
                    element.rotate(currentAngle * Math.PI / 180);
                    element.drawImage(image, canvas.width/2-image.width/2, canvas.height/2-image.height/2);
                    element.restore();
                }

here is my code http://plnkr.co/edit/Tvika6ygEBGmR9OMLSaT?p=preview

expected output

enter image description here

answered question

1 Answer

9

first you use scale so you must do somthing like

image.width * currentScale

then you must use

Math.abs() for positive value

or check image width /2 is not greater than canvas width /2

your current values is -1578 -2129

for this line

 element.drawImage(image, canvas.width/2-image.width/2, canvas.height/2-image.height/2);

posted this

Have an answer?

JD

Please login first before posting an answer.