einsteinsci
einsteinsci

Reputation: 1147

WPF image set boundaries

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.

Upvotes: 0

Views: 256

Answers (1)

Mitch
Mitch

Reputation: 22251

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>

Upvotes: 1

Related Questions