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

Incorrect handling of alpha channel in HTMLExport colors #667

Open
adrianlanzi opened this issue Jan 24, 2024 · 1 comment
Open

Incorrect handling of alpha channel in HTMLExport colors #667

adrianlanzi opened this issue Jan 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@adrianlanzi
Copy link

adrianlanzi commented Jan 24, 2024

Issue Summary:

When using HTMLExport in FastReport, the alpha channel in colors is not respected. This seems to be due to the usage of ColorTranslator.ToHtml() from the System.Drawing.Color library. I found a potential solution by modifying the HTMLColorCode function in the ExportUtils class to consider the alpha channel.

Steps to Reproduce:

Use HTMLExport in FastReport.
Export a report containing colors with alpha channels.

Expected Behavior:

The exported HTML should respect the alpha channel in colors.

Actual Behavior:

The alpha channel is not taken into account, leading to incorrect color representation in the exported HTML.

Proposed Solution:

Modify (and start using) the HTMLColorCode function in the ExportUtils class to include the alpha channel.

internal static string HTMLColor(Color color)
{
    return HTMLColorCode(color);
}

internal static string HTMLColorCode(Color color)
{
    string alpha = (color.A < 255) ? (color.A / 255.0).ToString("0.00", CultureInfo.InvariantCulture) : string.Empty;
    string htmlColorCode = (string.IsNullOrEmpty(alpha))
        ? $"rgb({color.R}, {color.G}, {color.B})"
        : $"rgba({color.R}, {color.G}, {color.B}, {alpha})";

    return htmlColorCode;
}

This modification address the issue and ensure that the alpha channel is considered during HTML export. I can create a PR if you need so... Already tested in my code

Additional Information:

FastReport Version: all
Environment: Windows 11, C#, Visual Studio 2022

Thank you for your attention to this matter.

@Alekarfes
Copy link

Thank you for pointing out the issue and submitting the code, we will examine it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants