WPF-How to show the cropped region of an image source in a <Image> control?

WPF How can I show a cropped ImageSource area in a control?

I have a vairable ImageSource in pixels. I have a rectangle with capillary images indicating which part of the image we will use. I don’t want to edit the image data directly, but I want my control to <Image>display only the cropped ImageSource area.

Does Microsoft provide an opportunity to automate this?
Any advice is appreciated!

+3
source share
1 answer

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>
+5

Source: https://habr.com/ru/post/1713773/


All Articles