Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG rendered to PNG is all black instead of a gradient #1105

Open
RobotGizmo opened this issue Dec 8, 2023 · 0 comments
Open

SVG rendered to PNG is all black instead of a gradient #1105

RobotGizmo opened this issue Dec 8, 2023 · 0 comments
Labels

Comments

@RobotGizmo
Copy link

RobotGizmo commented Dec 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants