BitmapDataExtensionsClip(IReadableBitmapData, Rectangle, Boolean) Method

Clips the specified source using the specified clippingRegion. Unlike the Clone methods, this one returns a wrapper, providing access only to the specified region of the original source.


Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 8.1.0
public static IReadableBitmapData Clip(
	this IReadableBitmapData source,
	Rectangle clippingRegion,
	bool disposeSource


source  IReadableBitmapData
The source bitmap data to be clipped.
clippingRegion  Rectangle
A Rectangle that specifies a region within the source.
disposeSource  Boolean
to dispose source when the result is disposed; otherwise, .

Return Value

An IReadableBitmapData that provides access only to the specified region withing the source.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IReadableBitmapData. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).


The RowSize property of the returned instance can be 0, indicating that the ReadRaw method cannot be used. It can occur if the left edge of the clipping is not zero.

Even if RowSize property of the returned instance is a nonzero value it can happen that it is too low to access all columns by the ReadRaw method. It can occur with indexed PixelFormats if the right edge of the clipping is not on byte boundary.


ArgumentNullExceptionsource is .
ArgumentOutOfRangeExceptionclippingRegion has no overlapping region with source bounds.

See Also