画像をクリップしようとしているように見えるので、ジオメトリに設定できる Clip プロパティを使用できます。
実際にもっと複雑なことを達成しようとしている場合は、WriteableBitmap を使用して Geometry を Bitmap にレンダリングし、OpacityMask で書き込み可能なビットマップを使用することができます。次の添付プロパティは、それを実現するのに役立ちます。
public class MyAttached
{
public static readonly DependencyProperty GeometryOpacityMaskProperty =
DependencyProperty.RegisterAttached("GeometryOpacityMask", typeof(Path), typeof(MyAttached), new PropertyMetadata(default(Path), GeometryOpacityMaskChanged));
private static void GeometryOpacityMaskChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
FrameworkElement uiElement = d as FrameworkElement;
Path path = e.NewValue as Path;
if (path != null && uiElement != null)
{
WriteableBitmap writeableBitmap = new WriteableBitmap((int)uiElement.Width, (int)uiElement.Height);
writeableBitmap.Render(path, new CompositeTransform());
writeableBitmap.Invalidate();
ImageBrush imageBrush=new ImageBrush();
imageBrush.ImageSource = writeableBitmap;
uiElement.OpacityMask = imageBrush;
}
}
public static void SetGeometryOpacityMask(UIElement element, Path value)
{
element.SetValue(GeometryOpacityMaskProperty, value);
}
public static Path GetGeometryOpacityMask(UIElement element)
{
return (Path)element.GetValue(GeometryOpacityMaskProperty);
}
}
次のように使用できます。
<Image
Height="150"
Width="200"
Source="sampleImages/Waterlilies.jpg"
Stretch="UniformToFill"
>
<phoneApp1:MyAttached.GeometryOpacityMask>
<Path>
<Path.Data>
<RectangleGeometry Rect="0.05,0.05 0.9,0.9" />
</Path.Data>
</Path>
</phoneApp1:MyAttached.GeometryOpacityMask>
</Image>