Nick
Nick

Reputation: 644

WPF DropShadowEffect - Unexpected Color Difference

I have a TextBlock with a DropShadowEffect. Certain shadow colors are showing darker than the color specified, almost as though they are tinted. However, this does not happen with every color. Does anyone know why, or a way to correct it?

Here's a very basic example:

<StackPanel>
    <StackPanel.Resources>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="FontSize" Value="100" />
            <Setter Property="Text" Value="THIS IS TEXT WITH A SHADOW" />
        </Style>
    </StackPanel.Resources>

    <!-- Expected Result -->
    <TextBlock Foreground="#FFFF0000">
        <TextBlock.Effect>
            <DropShadowEffect ShadowDepth="20" Color="#FFFF0000" />
        </TextBlock.Effect>
    </TextBlock>

    <!-- Unexpected Result -->
    <TextBlock Foreground="#FF005E20">
        <TextBlock.Effect>
            <DropShadowEffect ShadowDepth="20" Color="#FF005E20" />
        </TextBlock.Effect>
    </TextBlock>

</StackPanel>

Perhaps it has something to do with primary colors??

Upvotes: 3

Views: 717

Answers (1)

Michal Ciechan
Michal Ciechan

Reputation: 13888

Somewhere it is converting the DropShadowEffect into a specific Sc value.

The closer to 1 you are, the less the difference (hence FF/255/1 works absolutely fine)

From looking into this and researching about on ScRGB, the gamma value of ScRGB is around 2.2. Therefore when converting from RGB to ScRGB, you may need to divide by 255, then nth(2.2) root of the value to come up with the final value.

E.g.

value 5E is 94

94 / 255 = 0.36862745098039215686274509803922

2.2root of 94/255 = 0.635322735100355

0.635322735100355 * 255 = A2

Therefore when you set the ScG of the foreground to 5E, you need to set the DropShadowEffect to A2.

This is just my observation and what i came up with from my research.

Why did MS implement it like this? I HAVE NO IDEA

Sources:

Upvotes: 3

Related Questions