1 Answer

0 votes
by

Clipping a region is a process of displaying partial area of a region by setting the outline of a region. In WPF, the clipping has been extended to all elements that are inherited from UIElement that includes controls, images, panels, Windows, and Pages.

  1. Window.Clip>  
  2.    <EllipseGeometry Center="150,160" RadiusX="120" RadiusY="120" />  
  3. </Window.Clip>  

The following code snippet clips or crops an image to an ellipse.

  1. <Image Source="Garden.jpg">  
  2.     <Image.Clip>  
  3.         <EllipseGeometry Center="150,160" RadiusX="120" RadiusY="120" />   
  4.     </Image.Clip>  
  5. </Image>  

clipimage

  1. private void ClipImage()  
  2. {  
  3.     // Create a BitmapImage  
  4.     BitmapImage bmpImage = new BitmapImage();  
  5.     bmpImage.BeginInit();  
  6.     bmpImage.UriSource = new Uri(@ "C:\Images\Garden.jpg", UriKind.RelativeOrAbsolute);  
  7.     bmpImage.EndInit();  
  8.     // Clipped Image  
  9.     Image clippedImage = new Image();  
  10.     clippedImage.Source = bmpImage;  
  11.     EllipseGeometry clipGeometry = new EllipseGeometry(new Point(150, 160), 120, 120);  
  12.     clippedImage.Clip = clipGeometry;  
  13.     LayoutRoot.Children.Add(clippedImage);  
  14. }  

Related questions

0 votes
    What are Converters in WPF?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
    What is a Routed event?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
0 votes
    What is WPF Dependency Property and how can we use?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
    How can we improve the Performance of an ASP.NET Web Page?...
asked Apr 8, 2021 in Education by JackTerrance
...