public static Bitmap WPF_Copy(this Bitmap bmp, Rectangle rect) { if (!bmp.Fits(rect)) { return(null); } var src = bmp.ToBitmapSource(); Bitmap result = null; if (bmp.ToRectangle().EqualSize(rect)) { result = src.ToBitmapFast(System.Drawing.Imaging.PixelFormat.Format24bppRgb); } else { CroppedBitmap cropped = new CroppedBitmap(src, bmp.ToInt32Rect()); result = cropped.ToBitmapFast(System.Drawing.Imaging.PixelFormat.Format24bppRgb); } return(result); }