Axiom.Media.Image.CropImage C# (CSharp) Метод

CropImage() публичный Метод

Little utility function that crops an image (Doesn't alter the source image, returns a cropped representation)
public CropImage ( Image source, uint offsetX, uint offsetY, int width, int height ) : Image
source Image The source image
offsetX uint The X offset from the origin
offsetY uint The Y offset from the origin
width int The width to crop to
height int The height to crop to
Результат Image
		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 );
		}