How to prevent colors from blending?
Consider the following example:
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Top">
<Line Stroke="Red" X1="0" X2="100" Y1="50" Y2="50"/>
<Line Stroke="Red" X1="50" X2="50" Y1="0" Y2="100"/>
</Grid>
Despite the fact that both lines have SolidColorBrush and both have opacity=1, a color 开发者_运维知识库blending still occurs: The pixel at the point of intersection is of darker red color.
Why does it happen and how can I prevent it?
Thanks!
P.S Here is another example of the same code with the brushes explicitly defined:
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Top">
<Grid.Resources>
<Style TargetType="{x:Type Line}">
<Setter Property="Stroke">
<Setter.Value>
<SolidColorBrush Color="Red" Opacity="1" />
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Line X1="0" X2="100" Y1="50" Y2="50" />
<Line X1="50" X2="50" Y1="0" Y2="100" />
</Grid>
You might want to look into snapping to pixels. This is a feature of WPF that allows for some extra granularity in rendering. Say if we take a Line
and apply this:
<Line X1="0" X2="100" Y1="50" Y2="50" SnapsToDevicePixels="True"/>
As an example of what this serves to do, here's an image from the linked article:
精彩评论