Create a HUE color bar

强颜欢笑 提交于 2020-01-02 04:33:08

问题


I'm creating a color picker and I am at a stage where I need to create a HUE color bar:

One way to create it would be through gradient stops in XAML. For example:

<Rectangle Width="50" Height="100">
    <Rectangle.Fill>
        <LinearGradientBrush StartPoint="0.5,0.025" EndPoint="0.5,1" >
            <GradientStop Color="#FFFF0000" />
            <GradientStop Color="#FEFFFF00" Offset="0.15" />
            <GradientStop Color="#FE00FF00" Offset="0.3" />
            <GradientStop Color="#FE00FFFF" Offset="0.45" />
            <GradientStop Color="#FE0000FF" Offset="0.6" />
            <GradientStop Color="#FEFF00FF" Offset="0.85" />
            <GradientStop Color="#FFFF0000" Offset="1" />
        </LinearGradientBrush>
    </Rectangle.Fill>
</Rectangle>

The above will generate:

However, I am not sure whether the stops are correct.

Is there a convention on how to generate such a bar? Any advice would be highly appreciated.

Best Regards,

Casey


回答1:


It looks like your 2nd last stop is at a different interval (+0.25) to the previous ones (+0.15). You basically want the same gap between all stops to get the same effect (that colour bar is just a linear distribution).

Try this instead:

<Rectangle.Fill>
    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1.0" >
        <GradientStop Color="#FFFF0000" />
        <GradientStop Color="#FEFFFF00" Offset="0.167" />
        <GradientStop Color="#FE00FF00" Offset="0.333" />
        <GradientStop Color="#FE00FFFF" Offset="0.5" />
        <GradientStop Color="#FE0000FF" Offset="0.667" />
        <GradientStop Color="#FEFF00FF" Offset="0.833" />
        <GradientStop Color="#FFFF0000" Offset="1.0" />
    </LinearGradientBrush>
</Rectangle.Fill>

Which looks like:



来源:https://stackoverflow.com/questions/7584805/create-a-hue-color-bar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!