Essentially, I need to create a new bitmap from an existing one (this.Document.Bitmap) and then replace that existing one with the new one in the same property. I also would prefer to dispose of any extra memory this clone may cause, but am getting this error.
The statements outside of the using block are causing this exception to be thrown and I can't figure out why. Help?
An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll.
using (Bitmap b = this.Document.Bitmap.Clone(new RectangleF() { Width = (int)this.croppingBorder.Width, Height = (int)this.croppingBorder.Height, X = (int)Canvas.GetLeft(this.croppingBorder), Y = (int)Canvas.GetTop(this.croppingBorder) }, this.Document.Bitmap.PixelFormat))
{
this.Document.Bitmap = b;
BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(b.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
image1.Source = bs;
}
canvas1.Width = this.Document.Bitmap.Width;
canvas1.Height = this.Document.Bitmap.Height;