C# 切片图像wpf
在WPF中,我有一个图像,是否有方法应用这些坐标(图像的本地坐标): 0,10 20,0 20,20 仅选择性地显示由这些坐标构成的三角形 根据H.B.的建议,我可以使用不透明度遮罩,但我无法正确放置贴图,也无法裁剪以适应不透明度遮罩。 下面的例子应该是在伊利诺伊州C# 切片图像wpf,c#,wpf,image,xaml,C#,Wpf,Image,Xaml,在WPF中,我有一个图像,是否有方法应用这些坐标(图像的本地坐标): 0,10 20,0 20,20 仅选择性地显示由这些坐标构成的三角形 根据H.B.的建议,我可以使用不透明度遮罩,但我无法正确放置贴图,也无法裁剪以适应不透明度遮罩。 下面的例子应该是在伊利诺伊州 <Image Source="http://www.digital-topo-maps.com/county-map/united-states-map.gif" Stretch="None"> <Ima
<Image Source="http://www.digital-topo-maps.com/county-map/united-states-map.gif" Stretch="None">
<Image.Clip>
<PathGeometry>
<PathFigure StartPoint="444.806216983824,129.344961240310" IsClosed="True" IsFilled="True">
<LineSegment Point="445.976759660097,145.147286821705"/>
<LineSegment Point="431.344976206682,170.313953488372"/>
<LineSegment Point="447.732573674507,188.457364341085"/>
<LineSegment Point="458.852729099102,213.038759689923"/>
<LineSegment Point="469.387613185561,214.209302325581"/>
<LineSegment Point="481.093039948293,191.383720930233"/>
<LineSegment Point="479.337225933884,143.391472868217"/>
<LineSegment Point="477.581411919474,132.271317829457"/>
<LineSegment Point="444.806216983824,129.344961240310"/>
</PathFigure>
</PathGeometry>
</Image.Clip>
</Image>
您可以创建此三角形作为图像的or e、 g
这不是一个很好的解决方案,但似乎很有效…不透明遮罩似乎不支持我缺少的东西。不过,您可以创建一条路径,请参见我添加的示例。这太棒了,还有一个问题,有没有办法使它只占用路径边界。ie 20x20而不是完整图像大小?ThanksHmm,好问题,我想(无论如何,这是更合适的属性)可能会自动完成,但它看起来不像,可能通过绑定完成一些事情,可能需要另一个容器…我测试了一些东西,并使用
边距找到了一个选项,请参阅我的更新答案。。。(除非将对齐设置为除居中
或拉伸
之外的其他位置,否则位置可能会有点奇怪)
<Image.Clip>
<PathGeometry>
<PathFigure StartPoint="0,10">
<LineSegment Point="20,0" />
<LineSegment Point="20,20" />
</PathFigure>
</PathGeometry>
</Image.Clip>
<Image.Margin>
<Binding Path="Clip.Bounds" RelativeSource="{RelativeSource Self}">
<Binding.Converter>
<vc:BoundsToMarginConverter />
</Binding.Converter>
</Binding>
</Image.Margin>
public class BoundsToMarginConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Rect input = (Rect)value;
return new Thickness()
{
Left = -input.Left,
Right = -input.Right,
Top = -input.Top,
Bottom = -input.Bottom,
};
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}