0
图像我有这样的代码旋转用帆布背景
Allocate.prototype.Rotate = function() {
var canvas = document.getElementById("underCanvas");
var context = canvas.getContext("2d");
canvas.width = canvas.width;
context.lineWidth = "1";
context.save();
context.translate(this.drawStart.x + this.img.width * 0.5,
this.drawStart.y + this.img.height * 0.5);
context.rotate(Math.Pi/2);
context.translate(-(this.drawStart.x + this.img.width * 0.5),
-(this.drawStart.y + this.img.height * 0.5));
context.drawImage(this.img, this.drawStart.x, this.drawStart.y, this.drawStart.w, this.drawStart.h, this.drawStart.x, this.drawStart.y, this.drawStart.w, this.drawStart.h);
context.rect(this.drawStart.x, this.drawStart.y, this.drawStart.w, this.drawStart.h);
context.stroke();
context.restore();
}
什么,我觉得这个类的方法分配应该做的 - 是画由rectange内90度旋转图像(this.img)
。什么出来:它绘制一个变换的矩形,但图像仍然不旋转。为什么?
任何人都可以帮助我做到这一点吗?
此代码是类分配的一部分。我正在做一个网络绘画,并希望能够旋转分配的区域。谢谢。
rect里面的图像现在消失了。我认为它与我的drawImage-8参数绘图方式有关。试图改变它 –
@AlexanderCapone是的,你也需要调整。我只是在这里显示基本原则:-) – K3N
我编辑了有问题的代码。 你能解释为什么它不工作?因为我无法理解,没有任何东西在旋转! –