svg-net / SVG

Fork of the ms svg library

Home Page:http://svg-net.github.io/SVG/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SVG rendered to PNG is all black instead of a gradient

RobotGizmo opened this issue · comments

Description

When rendering the given SVG it is just all black instead of rendering the gradient correctly. It seems to be replacing the rgba colours with #000000 so there is no translucency.

Example data

You can just run this code to output the broken PNG file. I have also attached the SVG file as well just in case.

StringBuilder sb = new();
sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sb.AppendLine("<svg width=\"16px\" height=\"14px\" viewBox=\"0 0 16 14\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:bx=\"https://boxy-svg.com\">");
sb.AppendLine("	<defs>");
sb.AppendLine("		<bx:grid x=\"-1\" y=\"-1\" width=\"1\" height=\"1\"/>");
sb.AppendLine("		<linearGradient id=\"gradient-1\" bx:pinned=\"true\">");
sb.AppendLine("			<stop offset=\"0\" style=\"stop-color: rgba(0, 0, 0, 0.145);\"/>");
sb.AppendLine("			<stop offset=\"1\" style=\"stop-color: rgba(0, 0, 0, 0);\"/>");
sb.AppendLine("		</linearGradient>");
sb.AppendLine("		<linearGradient id=\"gradient-1-0\" gradientTransform=\"matrix(0, -0.830703, 0.333333, 0, 0.366667, 0.913773)\" x1=\"0.001\" y1=\"0.402\" x2=\"1.001\" y2=\"0.402\" xlink:href=\"#gradient-1\"/>");
sb.AppendLine("	</defs>");
sb.AppendLine("	<rect y=\"4.5\" width=\"15\" height=\"6.019\" style=\"stroke: rgb(0, 0, 0); fill: url('#gradient-1-0'); transform-box: fill-box; transform-origin: 49.9704% 52.7993%;\" x=\"0.5\"/>");
sb.AppendLine("	<line style=\"fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);\" x1=\"3.508\" y1=\"4\" x2=\"3.506\" y2=\"7\"/>");
sb.AppendLine("	<line style=\"fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);\" x1=\"6.502\" y1=\"4\" x2=\"6.5\" y2=\"7\"/>");
sb.AppendLine("	<line style=\"fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);\" x1=\"9.513\" y1=\"4\" x2=\"9.511\" y2=\"7\"/>");
sb.AppendLine("	<line style=\"fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);\" x1=\"12.507\" y1=\"4\" x2=\"12.505\" y2=\"7\"/>");
sb.AppendLine("</svg>");

SvgDocument svgDocument = SvgDocument.FromSvg<SvgDocument>(sb.ToString());
using (Bitmap bmp = new(16, 14, PixelFormat.Format32bppArgb))
{
    using (Graphics g = Graphics.FromImage(bmp))
    {
	    svgDocument.Draw(g, bmp.Size);
    }
    
    bmp.Save("Test.png");
}

File: AllBlackPng

Used Versions

v3.4.6, Windows 11, .NET 8