2

WPF-如何在控件中显示 ImageSource 的裁剪区域?

我有一个以像素为单位的可变大小的 ImageSource。我有一个经过计算的裁剪矩形,指示我们实际要使用多少图像。我不想直接编辑图像数据,但我希望我的<Image>控件只显示 ImageSource 的裁剪区域。

Microsoft 是否提供了一种自动化方法?
任何建议表示赞赏!

4

1 回答 1

5

使用CroppedBitmap

以下是它的用法示例:

   <Page.Resources>
      <!-- Define some image resources, for use as the image element source. -->
      <BitmapImage x:Key="masterImage" UriSource="/sampleImages/gecko.jpg" />
      <CroppedBitmap x:Key="croppedImage" 
         Source="{StaticResource masterImage}" SourceRect="30 20 105 50"/>
   </Page.Resources>
于 2009-07-28T16:32:59.127 回答