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

Specifying alpha channel in css color via hex causes result color to be black #1065

Open
nitz opened this issue Jun 22, 2023 · 0 comments
Open

Comments

@nitz
Copy link

nitz commented Jun 22, 2023

Description

If a CSS color is specified using a hex string that includes the alpha channel, the resulting color is black regardless of value. Specifying the alpha channel another way (e.g.: via rgb()) seems to work as expected though.

Example data

Reproduction example. (via LINQPad)

void Main()
{
	string template = 
"""
<svg viewBox="0 0 192 64" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <style type="text/css">
    text {{
      fill: {0};
    }}
    rect {{
      fill: #ffffff;
    }}
  </style>
  <rect width="100%" height="100%" />
  <text x="32" y="32" class="name">{1}</text>
</svg>
""";

	var svgs = new string[] {
		string.Format(template, "rgb(255, 0, 0, 255)", "Rgb red w/ alpha"),
		string.Format(template, "rgb(255, 0, 0, 128)", "Rgb red w/ alpha 128"),
		string.Format(template, "rgb(255, 0, 0)", "Rgb red w/ *no* alpha"),
		string.Format(template, "#ff0000ff", "Hex red w/ alpha 0xFF"),
		string.Format(template, "#ff000080", "Hex red w/ alpha 0x80"),
		string.Format(template, "#ff0000", "Hex red w/ *no* alpha"),
	};

	foreach (var svg in svgs)
	{
		var svgDoc = SvgDocument.FromSvg<SvgDocument>(svg);
		var bitmap = svgDoc.Draw();
		bitmap.Dump();
	}
}

Output result:
image

Used Versions

Svg v3.4.4 (Nuget)
.NET v7.0.5 (Roslyn v4.6.0-3.23259.8)
OS Windows 10 Pro For Workstations 22H2 19045.3086

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

No branches or pull requests

1 participant