This documentation is archived and is not being maintained.

Int32Rect Structure

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

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)

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



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



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



The width of the rectangle.



The height of the rectangle.

The Int32Rect type exposes the following members.

Public methodInt32RectInitializes a new instance of an Int32Rect with the specified X and Y coordinates and the specified Width and Height.

Public propertyStatic memberEmptyGets the empty rectangle, a special value that represents a rectangle with no position or area.
Public propertyHeightGets or sets the height of the rectangle.
Public propertyIsEmptyGets a value indicating whether the rectangle is empty.
Public propertyWidthGets or sets the width of the rectangle.
Public propertyXGets or sets the x-coordinate of the top-left corner of the rectangle.
Public propertyYGets or sets the y-coordinate of the top-left corner of the rectangle.

Public methodEquals(Int32Rect)Determines whether the specified rectangle is equal to this rectangle.
Public methodEquals(Object)Determines whether the specified rectangle is equal to this rectangle. (Overrides ValueType.Equals(Object).)
Public methodStatic memberEquals(Int32Rect, Int32Rect)Determines whether the specified rectangles are equal.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeCreates a hash code from this rectangle's X, Y, Width, and Height values. (Overrides ValueType.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberParseCreates an Int32Rect structure from the specified String representation.
Public methodToString()Creates a string representation of this Int32Rect. (Overrides ValueType.ToString().)
Public methodToString(IFormatProvider)Creates a string representation of this Int32Rect based on the supplied IFormatProvider.

Public operatorStatic memberEqualityCompares two rectangles for exact equality.
Public operatorStatic memberInequalityCompares two rectangles for inequality.

Explicit interface implemetationPrivate methodIFormattable.ToStringFormats the value of the current instance using the specified format.

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.

   <!-- 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"/>

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(     
   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">
      <CroppedBitmap Source="{StaticResource croppedImage}" 
         SourceRect="30 0 75 50"/>

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

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

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