public Image Inflate(int left, int top, int right, int bottom, BorderType borderType, uint borderValue) { // calculate and verify target area in source coordinates Rectangle bounds = Rectangle.FromLTRB( -left, -top, this.Width + right, this.Height + bottom); if (bounds.Width <= 0) { throw new ArgumentException("The new image width is invalid."); } if (bounds.Height <= 0) { throw new ArgumentException("The new image height is invalid."); } Image dst = new Image(bounds.Size, this); // calculate source area to copy from Rectangle srcarea = Rectangle.Intersect(bounds, this.Bounds); // calculate destination area to copy to Rectangle dstarea = Rectangle.Offset(srcarea, -bounds.X, -bounds.Y); Image.CopyArea(dst, dstarea.X, dstarea.Y, srcarea.Width, srcarea.Height, this, srcarea.X, srcarea.Y); // set border dst.SetBorder(dstarea, borderType, borderValue); dst.AppendTransform(new MatrixTransform(left, top)); return(dst); }