2014-07-07 180 views

回答

2

註釋的代碼和演示:http://jsfiddle.net/m1erickson/asT8x/

// clear the canvas 

ctx.clearRect(0,0,canvas.width,canvas.height); 

// save the context state 

ctx.save(); 

// translate to the coordinate point you wish to zoom in on 

ctx.translate(mouseX,mouseY); 

// scale the canvas to the desired zoom level 

ctx.scale(scale,scale); 

// draw the image with an offset of -mouseX,-mouseY 
// (offset to center image at the selected zoom point); 

ctx.drawImage(img,-mouseX,-mouseY); 

// restore the context to its untranslated/unrotated state 

ctx.restore(); 
+0

歐凱非常ynice但是如果我想放大和變換體位,這個例子只工作,開始改變位置 – user3797449