CroppedBitmap Constructor (BitmapSource, Int32Rect)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the CroppedBitmap class that has the specified Source and SourceRect.

Namespace:   System.Windows.Media.Imaging
Assembly:  PresentationCore (in PresentationCore.dll)

public CroppedBitmap(
	BitmapSource source,
	Int32Rect sourceRect


Type: System.Windows.Media.Imaging.BitmapSource

The Source of the new CroppedBitmap instance.

Type: System.Windows.Int32Rect

The SourceRect of the new CroppedBitmap instance.

Exception Condition

Occurs when source is null.

CroppedBitmap objects created using this constructor are automatically initialized. After initialization, property changes are ignored.

The following example shows how to use CroppedBitmap(BitmapSource, Int32Rect) to initialize a new instance of the CroppedBitmap class.

// 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
Available since 3.0
Return to top