0
votes

How do you display a rectangle of pixels on an image file in WPF? I want to 'crop in' on the region bounded by (8,8) and (15,15), and then display that region in a WPF Image control. Creating a BitmapImage and setting the SourceRect doesn't seem to work.

1

1 Answers

1
votes

That would be 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>