更新时间:2023-11-29 16:22:22
您有几种选择:
SVG 2具有isPointInFill()
方法.您可以在每个形状上调用它,以查看点是否在路径的填充范围内.但是我相信只有Chrome和Opera才实现了SVG2的这一新功能.
SVG 2 has the isPointInFill()
method. Which you can call on each shape to see if a point is within the fill of a path. However I believe only Chrome and Opera have implemented this new feature of SVG2.
https://developer.mozilla.org/zh- US/docs/Web/API/SVGGeometryElement/isPointInFill
您可以将SVG绘制到画布上,并使用isPointInPath()
方法.
You can draw your SVG to a Canvas and use the isPointInPath()
method.
https://developer.mozilla.org/zh- US/docs/Web/API/CanvasRenderingContext2D/isPointInPath
您可以将SVG绘制到画布上,并使用getImageData()
方法获取该特定像素的颜色.
You could draw the SVG to a Canvas and use the getImageData()
method to get the colour of that particular pixel.
https://developer.mozilla.org/zh- US/docs/Web/API/CanvasRenderingContext2D/getImageData
当然,您也可以通过某种方式自己计算来数字地进行计算.
And of course you can also do it numerically by calculating it yourself in some way.