我正在尝试使用drawImage()绘制图像,但使用的是矩阵变换,比如旋转或倾斜。有什么方法可以得到这个转换图像的预期界限吗?
发布于 2014-08-22 10:00:24
给定矩形的x,y,宽度,高度,rAngle,skewX,skewY:
旋转矩形的边框:
// rAngle is in radians
var absCos=Math.abs(Math.cos(rAngle));
var absSin=Math.abs(Math.sin(rAngle));
var centerX=x+width/2*Math.cos(rAngle)-height/2*Math.sin(rAngle);
var centerY=y+width/2*Math.sin(rAngle)+height/2*Math.cos(rAngle);
var newWidth=width*absCos+height*absSin;
var newHeight=width*absSin+height*absCos;
斜矩形的边框:
// skewX & skewY are in the range 0.00 to 1.00
var left = x * (1+skewX);
var top = y * (1+skewY);
var newWidth = width * (1+skewX);
var newHeight = height * (1+skewY);
https://stackoverflow.com/questions/25440681
复制