Tag: 不足操作exception

如何调试误导性的GDI OutOfMemoryexception?

我有一个调整位图大小的函数。 这是一个“面包和黄油”操作,我只是从另一个项目复制它: private Bitmap ResizeBitmap(Bitmap orig) { Bitmap resized = new Bitmap(this.Xsize, this.Ysize, PixelFormat.Format16bppGrayScale); resized.SetResolution(orig.HorizontalResolution, orig.VerticalResolution); using (Graphics g = Graphics.FromImage(resized)) { g.DrawImage(orig, 0, 0, resized.Width, resized.Height); } return resized; } 但是,我一直在Graphics g = Graphics.FromImage(resized)上获得OutOfMemoryexception。 我知道, 当谈到GDI时,OutOfMemoryexception通常会掩盖其他问题 。 我也非常清楚我想要resize的图像并不大(据我所知)GC在离开当前范围时应该没有问题收集实例。 无论如何,我现在已经玩了一段时间它现在看起来像这样: private Bitmap ResizeBitmap(Bitmap orig) { lock(orig) { using (Bitmap resized = new Bitmap(this.Xsize, this.Ysize, PixelFormat.Format16bppGrayScale)) […]