【发布时间】:2015-05-18 19:14:42
【问题描述】:
我在画布中加载了一张图片。旋转后,我无法(拖动)正确移动图像。实际上,它会移动,但它会根据图像的坐标平面移动。因此,将旋转 90 度的图像向右移动,向下移动,而不是像预期的那样向右移动。什么是解决这个问题的好方法?
这是我的绘图功能:
function draw(){
var im_width = parseInt( imageObj.width + resizeAmount );
var im_height = parseInt( imageObj.height + resizeAmount );
var rotationAmount = rotationVal - prevRotation;
prevRotation = rotationVal;
context.clearRect( 0, 0, canvas.width, canvas.height );
context.translate( canvas.width/2, canvas.height/2 );
context.rotate( rotationAmount * Math.PI / 180 );
context.translate( -canvas.width/2, -canvas.height/2 );
context.drawImage( imageObj, moveXAmount, moveYAmount, im_width, im_height );
}
这是jsdiddle,您可以在其中模拟它并了解我的意思。
PS:您可以使用左侧的滑块旋转图像。底部滑块用于缩放。如果图像没有出现在第一次加载中,请重新运行小提琴。
【问题讨论】:
标签: javascript jquery canvas html5-canvas filereader