Tag: 图克隆

位图克隆问题

请考虑以下代码来加载,修改和保存位图图像: using (Bitmap bmp = new Bitmap(“C:\\test.jpg”)) { bmp.RotateFlip(RotateFlipType.Rotate180FlipNone); bmp.Save(“C:\\test.jpg”); } 它运行没有任何例外。 但考虑一下: using (Bitmap bmp = new Bitmap(“C:\\test.jpg”)) { using (Bitmap bmpClone = (Bitmap)bmp.Clone()) { //You can replace “bmpClone” in the following lines with “bmp”, //exception occurs anyway bmpClone.RotateFlip(RotateFlipType.Rotate180FlipNone); bmpClone.Save(“C:\\test.jpg”); } } 它以ExternalException结束,并显示以下消息:“GDI +中发生了一般错误”。 这有什么不对? 对打开的文件有什么样的锁定? 如果是这样,为什么第一个块有效? 克隆System.Drawing.Bitmap的正确代码是什么,而我们可能需要在内存中编辑主对象或其克隆,并且仍然将它们都加载到内存中?