【发布时间】:2014-04-03 02:44:33
【问题描述】:
如何在 WPF 中的图像文件上显示像素矩形?我想在由 (8,8) 和 (15,15) 界定的区域上“裁剪”,然后在 WPF Image 控件中显示该区域。创建 BitmapImage 并设置 SourceRect 似乎不起作用。
【问题讨论】:
如何在 WPF 中的图像文件上显示像素矩形?我想在由 (8,8) 和 (15,15) 界定的区域上“裁剪”,然后在 WPF Image 控件中显示该区域。创建 BitmapImage 并设置 SourceRect 似乎不起作用。
【问题讨论】:
那就是CroppedBitmap:
<!-- from msdn -->
<!-- Chain a cropped bitmap off a previosly defined cropped image -->
<Image Width="200" Grid.Column="0" Grid.Row="3" Margin="5">
<Image.Source>
<CroppedBitmap Source="{StaticResource croppedImage}"
SourceRect="30 0 75 50"/>
</Image.Source>
</Image>
【讨论】:
CroppedBitmap 并将原始设置为Source。