1

我正在尝试检索剪辑区域的 dataURL,但只要矩形在该区域之外,生成的图像就会有边距(我猜它正在尝试包含矩形)。

以下是行为示例:https ://codesandbox.io/embed/clip-area-x24ci

(单击“导出”按钮或将黑色矩形移到剪切区域之外)

是否可以仅检索剪辑区域的内容?

4

1 回答 1

2

您可以设置、xyforwidth函数:heightnode.toDataURL()

const clipArea = {
  x: 100,
  y: 100,
  height: 200,
  width: 200
};

const dataURL = node.toDataURL({
  pixelRatio: 2,
  ...clipArea
});
于 2019-07-16T01:33:59.993 回答