WPF实现头像裁剪
WPF开发者QQ群: 340500857
前言
需要做一个用户选择头像进行裁剪后保存。
效果预览:
代码如下:
<Grid>
<Border x:Name="containerPanel">
<Canvas x:Name="DrawCanvas"
VerticalAlignment="Center"
Background="Transparent"
Width="{Binding ElementName=containerPanel,Path=ActualWidth}"
Height="{Binding ElementName=containerPanel,Path=ActualHeight}">
<Rectangle x:Name="rectImage" VerticalAlignment="Center" HorizontalAlignment="Center"
Width="{Binding ElementName=containerPanel,Path=ActualWidth}"
Height="{Binding ElementName=containerPanel,Path=ActualHeight}">
<Rectangle.Fill>
<ImageBrush ImageSource="{Binding ImageSource,RelativeSource={ RelativeSource AncestorType={x:Type local:ImageCutCustoms}}}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle VerticalAlignment="Center" HorizontalAlignment="Center"
Width="{Binding ElementName=rectImage,Path=ActualWidth}"
Height="{Binding ElementName=rectImage,Path=ActualHeight}"
Fill="#99000000"/>
<Rectangle VerticalAlignment="Center" HorizontalAlignment="Center"
Width="{Binding ElementName=containerPanel,Path=ActualWidth}"
Height="{Binding ElementName=containerPanel,Path=ActualHeight}">
<Rectangle.Fill>
<