public Image CropImage( Image source, uint offsetX, uint offsetY, int width, int height )
{
if ( offsetX + width > source.Width )
return source;
else if ( offsetY + height > source.Height )
return source;
int bpp = PixelUtil.GetNumElemBytes( source.Format );
byte[] srcData = source.Data;
byte[] dstData = new byte[ width * height * bpp ];
int srcPitch = source.RowSpan;
int dstPitch = width * bpp;
for ( int row = 0; row < height; row++ )
{
for ( int col = 0; col < width * bpp; col++ )
{
dstData[ ( row * dstPitch ) + col ] = srcData[ ( ( row + offsetY ) * srcPitch ) + ( offsetX * bpp ) + col ];
}
}
return ( new Image() ).FromDynamicImage( dstData, width, height, source.Format );
}