有没有办法在一个方向上缩放图像


Is there a way to scale image in one direction?

是否有办法在一个方向上缩放。通常scale函数在x和y方向上相等地缩放画布,但如果我想取一条折线,或者一组线,并在x方向上缩放而不是在y方向上缩放,我该怎么做?

最好的例子是http://www.giffits.de/logoplacer/lpl.php?cv=1760&mandantid=0&il=55744_1,55744_2&itemCode=55744&itemname=Carina&t=1469093996653

这应该更容易,但你可以这样做:

  • 将y刻度保存为值;
  • 在改变时更新y刻度;
  • 返回ctx.scale(x, y)中的y刻度。

如果ctx.scale(x, y)中没有定义y参数,则y刻度将设置为0。所以这是你能做的最小的事情。


var scaleY = 1;
/* change the x scale only */
ctx.scale(1, scaleY);
/* change both coordinates scale */
scaleY = 3;
ctx.scale(2, scaleY);