多次调用此函数时,任何一个 try 块都会不断抛出错误。这发生在随机时间,尤其是在重复调用时。
//CameraCanvas: Class bitmap variable
//Canvas: Class bitmap imported through open file dialog
public void UpdateCamera()
{
try
{
CameraCanvas = new Bitmap(CameraWidthHeight.X, CameraWidthHeight.Y, PixelFormat.Format32bppArgb);
}
catch(Exception ex)
{
throw ex;
}
Graphics g = Graphics.FromImage(CameraCanvas);
g.InterpolationMode = InterpolationMode.NearestNeighbor;
//Draw it
Bitmap drawImage = Canvas;
g.DrawImage(drawImage, new PointF(0f,0f));
try
{
CameraCanvas = new Bitmap(CameraWidthHeight.X, CameraWidthHeight.Y, g);
}
catch(Exception ex)
{
throw ex;
}
g.Dispose();
}
我尝试了很多东西,但没有一个有效。没有任何代码涉及流或类似的东西。下面是通过表单构造函数中的打开文件对话框将画布作为位图导入的代码。
Bitmap source;
try
{
OpenFileDialog of = new OpenFileDialog();
if(of.ShowDialog() == DialogResult.OK)
{
source = new Bitmap(of.FileName);
Canvas = source;
this.TopLevel = true;
}
}
catch(Exception ex)
{
throw ex;
}