0

我不知道是否有人真正使用它,但我想使用DOMMatrix对象在 HTMLCanvas 2d 上下文上定位和缩放SVG 路径。

var path = new Path2D("M0.55,0.55 C0.55,0.55,0.45,0.55,0.45,0.55 C0.45,0.55,0.45,0.45,0.45,0.45 C0.45,0.45,0.55,0.45,0.55,0.45 C0.55,0.45,0.55,0.55,0.55,0.55");

var matrix = new DOMMatrix();
matrix.translateSelf(50,50);
matrix.scaleSelf(5); // <-- THIS IS THE PROBLEM!

//add matrix to SVG-Path 
var draw = new Path2D();
draw.addPath(path, matrix);

ctx.strokeStyle = "lime";
ctx.stroke(draw);

现在,由于某种原因 scaleSelf() 破坏了矩阵。对象属性用 NAN 填充。

缩放前

缩放前

缩放后

在此处输入图像描述

有人解决了吗?(浏览器:火狐开发)

var matrix = new DOMMatrix();
matrix.translateSelf(50,50);
console.log("After translate: ", matrix);
matrix.scaleSelf(5); // <-- THIS IS THE PROBLEM!
console.log("After scale: ", matrix);

4

0 回答 0