Skip to content

Incorrect handling of alpha channel in HTMLExport colors #667

@adrianlanzi

Description

@adrianlanzi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions