本质上,我需要从一个现有的位图(this.Document.Bitmap)创建一个新的位图,然后在同一属性中用新的位图替换该现有的位图。我也希望处置此克隆可能导致的任何额外内存,但是却收到此错误。
using块之外的语句导致引发此异常,我不知道为什么。帮助?
System.Drawing.dll中发生了类型为'System.ArgumentException'的未处理的异常。
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;
这是您正在处理出现的问题的方法:
b
Document.B
用克隆覆盖,但忘了处置旧值using
块时,b
也会Document.B
丢弃该位图,因此尝试获取该位图的尺寸会失败。b.GetHBitmap()
复制像素后,应进行处置。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句