How to get background color of SVG converted properly into Canvas

前端 未结 3 1725
迷失自我
迷失自我 2020-12-21 10:38

Im converting a d3 svg object with use of canvg library to an canvas and display it as an image (png).

The resulting image has a transparent background, which is not

3条回答
  •  没有蜡笔的小新
    2020-12-21 11:02

    I have ran in to this before. As you know the CSS doesn't pass get put in the DOM, so it's not read by the conversion. So you have to do inline styling instead. But the way you are currently doing it is incorrect.

    So instead of using :

    .attr("style","background: white;").
    

    You have to set the style like this :

    .style('fill', 'white'); 
    

    That should work fine :)

提交回复
热议问题