Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In WPF, view a portion of an image

Tags:

image

wpf

We have an image where we create view box coordinates that are topleft/bottom right points within the image that are setup to allow for viewing portions of an image at different times in our application. In WPF, how do we load an image, and with topleft/bottom right points within that image, only show the portion of the image within that view box?

like image 708
FarrEver Avatar asked Feb 04 '10 15:02

FarrEver


People also ask

How do I use resource image in WPF XAML?

Set your Image source like this: <Image Source={Binding {x:Static UI:Resources. Search}} /> where 'Search' is name of the resource. Save this answer.


1 Answers

You can do this with a CroppedBitmap:

<Image>
  <Image.Source>
    <CroppedBitmap Source="<path to source image>" SourceRect="20,20,50,50"/>
  </Image.Source>
</Image>

This will display the 50x50 region of the image starting at position (20,20)

like image 163
Kris Pruden Avatar answered Oct 19 '22 09:10

Kris Pruden