SVG 上图像之间的间隙

gaps between images on svg

提问人:practicemakesperfect 提问时间:11/6/2023 最后编辑:practicemakesperfect 更新时间:11/6/2023 访问量:24

问:

我曾经将一堆彼此相邻的方形图像布置成 ,但似乎有这些微小的间隙(在下图中以黄色突出显示)我无法摆脱。如何删除它们?svg.append(g)<g>

async function drawBackground() {
var array = await randomArray();
for (var i=0; i<array.length; i++) {
  var positionX = paddingLeft + i % imgPerRowCount * imgWidth;
  var positionY = Math.floor(i / imgPerRowCount) * imgHeight + scrollY;
  layerBackground.append("image")
    .attr("x", positionX)
    .attr("y", positionY)
    .attr("width", imgWidth)
    .attr("height", imgHeight)
    .attr("xlink:href", imgPath[array[i]]);
}

我看到了其他关于设置方形图像的父 div 以解决图像之间的间隙的帖子,但由于这是在 svg 上完成的,因此此方法不起作用。font-size: 0;

enter image description here

JavaScript 图像 SVG 绘图

评论

0赞 Keith 11/6/2023
如今,浏览器中的图形使用亚像素映射,因此将一个图像与另一个图像对齐以使其完美可能很棘手,浏览器缩放也会影响这一点。但是看看你上面显示的内容,也许不是在你的SVG上使背景颜色为灰色,而是让它保持透明,并使你放置SVG的东西有灰色的背景。
0赞 practicemakesperfect 11/6/2023
谢谢你的回答。黑色部分实际上是切出/透明的,所以现在我依靠灰色来赋予它定义......
0赞 Keith 11/6/2023
对不起,不知道你在那里说什么..我并不是说不要使用灰色,而是将灰色放在你的而不是 SVG 上。如果我错过了理解您的问题,您能否尝试创建一个简单的片段来显示该问题。layerBackground
0赞 herrstrietzel 11/7/2023
请添加一个运行示例,包括加载的 svg 图块的示例。间隙似乎来自加载的 svg 文件中的填充。<image>

答: 暂无答案