WPF DropShadowEffect - 意外的颜色差异 [英] WPF DropShadowEffect - Unexpected Color Difference

查看:1221
本文介绍了WPF DropShadowEffect - 意外的颜色差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextBlock与DropShadowEffect。某些阴影颜色显示比指定的颜色深,几乎就像它们有色。然而,这不会发生在每种颜色。



这里有一个非常基本的例子:

 & lt; StackPanel> 
< StackPanel.Resources>
< Style TargetType ={x:Type TextBlock}>
< Setter Property =FontSizeValue =100/>
< Setter Property =TextValue =THIS IS TEXT WITH A SHADOW/>
< / Style>
< /StackPanel.Resources>

<! - 预期结果 - >
< TextBlock Foreground =#FFFF0000>
< TextBlock.Effect>
< DropShadowEffect ShadowDepth =20Color =#FFFF0000/>
< /TextBlock.Effect>
< / TextBlock>

<! - 意外结果 - >
< TextBlock Foreground =#FF005E20>
< TextBlock.Effect>
< DropShadowEffect ShadowDepth =20Color =#FF005E20/>
< /TextBlock.Effect>
< / TextBlock>

< / StackPanel>

也许它与原色有关。



距离1越近,你就越容易看到。减少差异(因此FF / 255/1工作完全正常)



从ScrGB的研究和ScrGB的研究,ScRGB的gamma值约为2.2。因此,当从RGB转换为ScRGB时,您可能需要除以255,然后除以值的nth(2.2)根以得出最终值。



 值5E为94 

94/255 = 0.36862745098039215686274509803922

根的94/255 = 0.635322735100355

0.635322735100355 * 255 = A2

当你将前景的ScG设置为5E时,你需要将DropShadowEffect设置为A2。



这只是我的观察和我从研究中得出的结果。



为什么MS这样实现? I HAVE NO IDEA



资料来源:




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??

解决方案

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:

这篇关于WPF DropShadowEffect - 意外的颜色差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆