Commit 0fdda9d7 LN

1

1 个父辈 b3c9937e
...@@ -31,7 +31,9 @@ namespace AOI ...@@ -31,7 +31,9 @@ namespace AOI
/// <returns></returns> /// <returns></returns>
public GraphicsPath GetSearchPath() public GraphicsPath GetSearchPath()
{ {
if(RoiPath != null && SearchPathZoom > 0) try
{
if (RoiPath != null && SearchPathZoom > 0)
{ {
GraphicsPath SearchPath = new GraphicsPath(RoiPath.PathPoints, RoiPath.PathTypes); GraphicsPath SearchPath = new GraphicsPath(RoiPath.PathPoints, RoiPath.PathTypes);
Matrix matrix = new Matrix(); Matrix matrix = new Matrix();
...@@ -53,6 +55,10 @@ namespace AOI ...@@ -53,6 +55,10 @@ namespace AOI
return SearchPath; return SearchPath;
} }
return RoiPath; return RoiPath;
}catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}return null;
} }
/// <summary> /// <summary>
......
...@@ -38,14 +38,14 @@ namespace AccAOI ...@@ -38,14 +38,14 @@ namespace AccAOI
// BaseImg = image; // BaseImg = image;
// Project = new AoiProject(image); // Project = new AoiProject(image);
string result = ""; string result = "";
Project= AoiProject.Load(programPath,out result); Project = AoiProject.Load(programPath, out result);
if (!result.Equals("")) if (!result.Equals(""))
{ {
MessageBox.Show("加载项目" + programPath + "失败:\r\n" + result); MessageBox.Show("加载项目" + programPath + "失败:\r\n" + result);
} }
else else
{ {
currProjectFileName= programPath; currProjectFileName = programPath;
} }
} }
if (image != null) if (image != null)
...@@ -133,7 +133,7 @@ namespace AccAOI ...@@ -133,7 +133,7 @@ namespace AccAOI
} //将图片保存到本地重新加载 } //将图片保存到本地重新加载
// string filePath = Application.StartupPath + @"\aimage\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + DateTime.Now.Millisecond.ToString().PadLeft(3, '0') ; // string filePath = Application.StartupPath + @"\aimage\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + DateTime.Now.Millisecond.ToString().PadLeft(3, '0') ;
string filePath = Application.StartupPath + @"\aimage\"; string filePath = Application.StartupPath + @"\aimage\";
string fileName = @"\test.bmp"; string fileName = @"\base.bmp";
using (Bitmap img = CameraManager.GetCamerImage(camera)) using (Bitmap img = CameraManager.GetCamerImage(camera))
{ {
if (img != null) if (img != null)
...@@ -145,6 +145,11 @@ namespace AccAOI ...@@ -145,6 +145,11 @@ namespace AccAOI
} }
img.Save(filePath + fileName, ImageFormat.Bmp); img.Save(filePath + fileName, ImageFormat.Bmp);
} }
else
{
MessageBox.Show("获取图片失败");
return;
}
} }
GC.Collect(); GC.Collect();
Image file = (Image)Image.FromFile(filePath + fileName); Image file = (Image)Image.FromFile(filePath + fileName);
...@@ -163,7 +168,7 @@ namespace AccAOI ...@@ -163,7 +168,7 @@ namespace AccAOI
btnImageChange_Click(null, null); btnImageChange_Click(null, null);
} }
} }
catch(Exception ex) catch (Exception ex)
{ {
Console.WriteLine("btnGetCameraImg_Click Error:" + ex.ToString()); Console.WriteLine("btnGetCameraImg_Click Error:" + ex.ToString());
MessageBox.Show(ex.ToString()); MessageBox.Show(ex.ToString());
...@@ -318,7 +323,7 @@ namespace AccAOI ...@@ -318,7 +323,7 @@ namespace AccAOI
aoiControl.FormBorderStyle = FormBorderStyle.None; aoiControl.FormBorderStyle = FormBorderStyle.None;
aoiControl.StartPosition = FormStartPosition.CenterParent; aoiControl.StartPosition = FormStartPosition.CenterParent;
aoiControl.Location = new Point(0, 0); aoiControl.Location = new Point(0, 0);
aoiControl.BImageBox=this.imageBox1; aoiControl.BImageBox = this.imageBox1;
aoiControl.AoiInfo = method; aoiControl.AoiInfo = method;
aoiControl.Size = panAoi.Size; aoiControl.Size = panAoi.Size;
aoiControl.TitleName = method.MethodName; aoiControl.TitleName = method.MethodName;
...@@ -332,14 +337,14 @@ namespace AccAOI ...@@ -332,14 +337,14 @@ namespace AccAOI
//Image threshImage = CutImage(imageBox1.Image, currPath); //Image threshImage = CutImage(imageBox1.Image, currPath);
//cutImage = threshImage; //cutImage = threshImage;
aoiControl.SetCurrPath(currPath,true); aoiControl.SetCurrPath(currPath, true);
} }
aoiControl.Show(); aoiControl.Show();
aoiControl.ShowAoiInfo(); aoiControl.ShowAoiInfo();
} }
private void SaveCurrAoi() private void SaveCurrAoi()
{ {
if (aoiControl != null &&aoiControl.Visible) if (aoiControl != null && aoiControl.Visible)
{ {
AoiMethod method = aoiControl.GetAoiInfo(); AoiMethod method = aoiControl.GetAoiInfo();
...@@ -383,7 +388,8 @@ namespace AccAOI ...@@ -383,7 +388,8 @@ namespace AccAOI
{ {
aoiList.Index = index; aoiList.Index = index;
ShowAoi(Project.methodMap[key]); ShowAoi(Project.methodMap[key]);
}index++; }
index++;
} }
} }
if (imageBox1.Visible.Equals(false)) if (imageBox1.Visible.Equals(false))
...@@ -435,8 +441,9 @@ namespace AccAOI ...@@ -435,8 +441,9 @@ namespace AccAOI
} }
currPath = imageBox1.SelectionRegion; currPath = imageBox1.SelectionRegion;
aoiControl.SetCurrPath( currPath); aoiControl.SetCurrPath(currPath);
}catch(Exception ex) }
catch (Exception ex)
{ {
} }
...@@ -486,7 +493,7 @@ namespace AccAOI ...@@ -486,7 +493,7 @@ namespace AccAOI
} }
if (this.aoiControl != null) if (this.aoiControl != null)
{ {
DialogResult result= MessageBox.Show("确定删除 " + aoiControl.AoiInfo.MethodName + " ?", "确认提示", MessageBoxButtons.OKCancel); DialogResult result = MessageBox.Show("确定删除 " + aoiControl.AoiInfo.MethodName + " ?", "确认提示", MessageBoxButtons.OKCancel);
if (result.Equals(DialogResult.OK)) if (result.Equals(DialogResult.OK))
{ {
if (Project.methodMap.ContainsKey(aoiControl.AoiInfo.MethodName)) if (Project.methodMap.ContainsKey(aoiControl.AoiInfo.MethodName))
...@@ -561,11 +568,32 @@ namespace AccAOI ...@@ -561,11 +568,32 @@ namespace AccAOI
MessageBox.Show("清先选择相机"); MessageBox.Show("清先选择相机");
return; return;
} }
Bitmap img = CameraManager.GetCamerImage(camera);
string filePath = Application.StartupPath + @"\aimage\";
string fileName = @"\test.bmp";
using (Bitmap img = CameraManager.GetCamerImage(camera))
{
if (img != null) if (img != null)
{ {
string path = Path.GetFullPath(filePath);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
img.Save(filePath + fileName, ImageFormat.Bmp);
}
else
{
MessageBox.Show("获取图片失败");
return;
}
}
GC.Collect();
Image file = (Image)Image.FromFile(filePath + fileName);
TestImage = new Bitmap(file);
file.Dispose();
//读取图片内容 //读取图片内容
TestImage = (Image)img.Clone();
testImageBox1.Image = TestImage; testImageBox1.Image = TestImage;
if (testImageBox1.Visible.Equals(false)) if (testImageBox1.Visible.Equals(false))
{ {
...@@ -573,5 +601,4 @@ namespace AccAOI ...@@ -573,5 +601,4 @@ namespace AccAOI
} }
} }
} }
}
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!