我开发了一个Windows Mobile 6.5应用程序。 在我的应用程序相机选项可用,我需要捕获这么多的图像,但在捕获5个图像后,它会抛出异常,如" 初始化失败"
这是我的代码段。
CameraCaptureDialog cameraCapture = new CameraCaptureDialog();
cameraCapture.Resolution = new Size(240, 320);
cameraCapture.Owner = null;
string directoryString = @"\My Documents";
if (Directory.Exists(directoryString))
{
cameraCapture.InitialDirectory = @"\My Documents\SurveyImages";
}
else
{
string activeDir = @"\My Documents\";
string newpath = System.IO.Path.Combine(activeDir, "SurveyImages");
System.IO.Directory.CreateDirectory(newpath);
cameraCapture.InitialDirectory = @"\My Documents\SurveyImages";
}
cameraCapture.StillQuality = CameraCaptureStillQuality.High;
cameraCapture.Mode = CameraCaptureMode.Still;
if (DialogResult.OK == cameraCapture.ShowDialog())
{
}
我如何解决这个问题。
答案 0 :(得分:0)
更改您的代码
CameraCaptureDialog cameraCapture = new CameraCaptureDialog();
cameraCapture.Resolution = new Size(240, 320);
cameraCapture.Owner = null;
string directoryString = @"\My Documents";
if (Directory.Exists(directoryString))
{
cameraCapture.InitialDirectory = @"\My Documents\SurveyImages";
}
else
{
string activeDir = @"\My Documents\";
string newpath = System.IO.Path.Combine(activeDir, "SurveyImages");
System.IO.Directory.CreateDirectory(newpath);
cameraCapture.InitialDirectory = @"\My Documents\SurveyImages";
}
cameraCapture.StillQuality = CameraCaptureStillQuality.High;
cameraCapture.Mode = CameraCaptureMode.Still;
if (DialogResult.OK == cameraCapture.ShowDialog())
{
???
}
到
CameraCaptureDialog cameraCapture = new CameraCaptureDialog();
cameraCapture.Resolution = new Size(240, 320);
cameraCapture.Owner = null;
string directoryString = @"\My Documents";
if (Directory.Exists(directoryString))
{
cameraCapture.InitialDirectory = @"\My Documents\SurveyImages";
}
else
{
string activeDir = @"\My Documents\";
string newpath = System.IO.Path.Combine(activeDir, "SurveyImages");
System.IO.Directory.CreateDirectory(newpath);
cameraCapture.InitialDirectory = @"\My Documents\SurveyImages";
}
cameraCapture.StillQuality = CameraCaptureStillQuality.High;
cameraCapture.Mode = CameraCaptureMode.Still;
if (DialogResult.OK == cameraCapture.ShowDialog())
{
???
}
cameraCapture.Dispose();
cameraCapture=null;
如果这对您不起作用,请提供更多代码。此更改可确保在您尝试创建新对象之前完全清除cameraCapture对象。