Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Int32Rect Structure

Describes the width, height, and location of an integer rectangle.

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[SerializableAttribute]
[TypeConverterAttribute(typeof(Int32RectConverter))]
public struct Int32Rect : IFormattable
<object property="X,Y,Width,Height"/>
- or 
<object property="Empty"/>
You can also use whitespace instead of commas to delimit values. Whitespace can also be used with a comma delimited value set.

XAML Values

X

System.Int32

The x-coordinate of the top-left corner of the rectangle.

Y

System.Int32

The y-coordinate of the top-left corner of the rectangle.

Width

System.Int32

The width of the rectangle.

Height

System.Int32

The height of the rectangle.

This example shows how to crop an image using CroppedBitmap.

CroppedBitmap is primarily used when encoding a cropped version of an image to save out to a file. To crop an image for display purposes see the How to: Create a Clip Region topic.

The following Extensible Application Markup Language (XAML) defines resources used within the samples below.

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

The following example creates an image using a CroppedBitmap as its source.

<!-- Use the cropped image resource as the images source -->
<Image Width="200" Source="{StaticResource croppedImage}" 
   Margin="5" Grid.Column="0" Grid.Row="1" />
// Create an Image element.
Image croppedImage = new Image();
croppedImage.Width = 200;
croppedImage.Margin = new Thickness(5);

// Create a CroppedBitmap based off of a xaml defined resource.
CroppedBitmap cb = new CroppedBitmap(     
   (BitmapSource)this.Resources["masterImage"],
   new Int32Rect(30, 20, 105, 50));       //select region rect
croppedImage.Source = cb;                 //set image source to cropped

The CroppedBitmap can also be used as the source of another CroppedBitmap, chaining the cropping. Note that the SourceRect uses values that are relative to the source cropped bitmap and not the initial image.

<!-- 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>
// Create an Image element.
Image chainImage = new Image();
chainImage.Width = 200;
chainImage.Margin = new Thickness(5);

// Create the cropped image based on previous CroppedBitmap.
CroppedBitmap chained = new CroppedBitmap(cb,
   new Int32Rect(30, 0, (int)cb.Width-30, (int)cb.Height)); 
// Set the image's source.
chainImage.Source = chained;

For the complete sample, see Image Element Sample.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.