Commit 0fdda9d7 LN

1

1 个父辈 b3c9937e
...@@ -31,28 +31,34 @@ namespace AOI ...@@ -31,28 +31,34 @@ namespace AOI
/// <returns></returns> /// <returns></returns>
public GraphicsPath GetSearchPath() public GraphicsPath GetSearchPath()
{ {
if(RoiPath != null && SearchPathZoom > 0) try
{ {
GraphicsPath SearchPath = new GraphicsPath(RoiPath.PathPoints, RoiPath.PathTypes); if (RoiPath != null && SearchPathZoom > 0)
Matrix matrix = new Matrix(); {
matrix.Scale(SearchPathZoom, SearchPathZoom); GraphicsPath SearchPath = new GraphicsPath(RoiPath.PathPoints, RoiPath.PathTypes);
SearchPath.Transform(matrix); Matrix matrix = new Matrix();
matrix.Scale(SearchPathZoom, SearchPathZoom);
SearchPath.Transform(matrix);
var oldBounds = this.RoiPath.GetBounds(); var oldBounds = this.RoiPath.GetBounds();
var newBounds = SearchPath.GetBounds(); var newBounds = SearchPath.GetBounds();
var oldCenterX = oldBounds.X + oldBounds.Width / 2; var oldCenterX = oldBounds.X + oldBounds.Width / 2;
var oldCenterY = oldBounds.Y + oldBounds.Height / 2; var oldCenterY = oldBounds.Y + oldBounds.Height / 2;
var newCenterX = newBounds.X + newBounds.Width / 2; var newCenterX = newBounds.X + newBounds.Width / 2;
var newCenterY = newBounds.Y + newBounds.Height / 2; var newCenterY = newBounds.Y + newBounds.Height / 2;
matrix.Reset(); matrix.Reset();
matrix.Translate(oldCenterX - newCenterX, oldCenterY - newCenterY); matrix.Translate(oldCenterX - newCenterX, oldCenterY - newCenterY);
SearchPath.Transform(matrix); SearchPath.Transform(matrix);
return SearchPath; return SearchPath;
} }
return RoiPath; return RoiPath;
}catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}return null;
} }
/// <summary> /// <summary>
......
...@@ -35,17 +35,17 @@ namespace AccAOI ...@@ -35,17 +35,17 @@ namespace AccAOI
this.WindowState = FormWindowState.Maximized; this.WindowState = FormWindowState.Maximized;
if (!programPath.Equals("")) if (!programPath.Equals(""))
{ {
// 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)
...@@ -53,7 +53,7 @@ namespace AccAOI ...@@ -53,7 +53,7 @@ namespace AccAOI
if (Project != null) if (Project != null)
{ {
Project.standardImage = image; Project.standardImage = image;
} }
} }
DefaultPath = defaultPath; DefaultPath = defaultPath;
...@@ -74,8 +74,8 @@ namespace AccAOI ...@@ -74,8 +74,8 @@ namespace AccAOI
file.Dispose(); file.Dispose();
imageBox1.Image = BaseImg; imageBox1.Image = BaseImg;
} }
foreach (string str in CameraManager.hikNameList) foreach (string str in CameraManager.hikNameList)
{ {
cmbCameraList.ItemAdd(str); cmbCameraList.ItemAdd(str);
...@@ -86,9 +86,9 @@ namespace AccAOI ...@@ -86,9 +86,9 @@ namespace AccAOI
} }
if (Project != null) if (Project != null)
{ {
ShowPorject(); ShowPorject();
} }
} }
private void btnOpenImage_Click(object sender, EventArgs e) private void btnOpenImage_Click(object sender, EventArgs e)
{ {
...@@ -96,7 +96,7 @@ namespace AccAOI ...@@ -96,7 +96,7 @@ namespace AccAOI
openDialog.Title = "打开本地图片"; openDialog.Title = "打开本地图片";
openDialog.Filter = "All Supported Images (*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png)|*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png|Bitmaps (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|Graphics Interchange Format (*.gif)|*.gif|Joint Photographic Experts (*.jpg)|*.jpg|Portable Network Graphics (*.png)|*.png|All Files (*.*)|*.*"; openDialog.Filter = "All Supported Images (*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png)|*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png|Bitmaps (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|Graphics Interchange Format (*.gif)|*.gif|Joint Photographic Experts (*.jpg)|*.jpg|Portable Network Graphics (*.png)|*.png|All Files (*.*)|*.*";
openDialog.DefaultExt = "png"; openDialog.DefaultExt = "png";
//openDialog.DefaultExt = "png"; //openDialog.DefaultExt = "png";
System.Windows.Forms.DialogResult result = openDialog.ShowDialog(); System.Windows.Forms.DialogResult result = openDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel) if (result == System.Windows.Forms.DialogResult.Cancel)
...@@ -131,9 +131,9 @@ namespace AccAOI ...@@ -131,9 +131,9 @@ namespace AccAOI
MessageBox.Show("清先选择相机"); MessageBox.Show("清先选择相机");
return; return;
} //将图片保存到本地重新加载 } //将图片保存到本地重新加载
// 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,12 +145,17 @@ namespace AccAOI ...@@ -145,12 +145,17 @@ 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);
BaseImg = new Bitmap(file); BaseImg = new Bitmap(file);
file.Dispose(); file.Dispose();
// BaseImg = (Image)Image.FromFile(filePath+ file).Clone(); // BaseImg = (Image)Image.FromFile(filePath+ file).Clone();
//读取图片内容 //读取图片内容
//BaseImg = (Image)img.Clone(); //BaseImg = (Image)img.Clone();
if (Project != null) if (Project != null)
...@@ -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());
...@@ -200,7 +205,7 @@ namespace AccAOI ...@@ -200,7 +205,7 @@ namespace AccAOI
this.imageBox1.Image.Dispose(); this.imageBox1.Image.Dispose();
this.imageBox1.Image = null; this.imageBox1.Image = null;
} }
GC.Collect(); GC.Collect();
} }
else else
...@@ -221,7 +226,7 @@ namespace AccAOI ...@@ -221,7 +226,7 @@ namespace AccAOI
{ {
return; return;
} }
string fileName = openDialog.FileName; string fileName = openDialog.FileName;
// Project = new AoiProject(BaseImg); // Project = new AoiProject(BaseImg);
string msg = ""; string msg = "";
...@@ -232,7 +237,7 @@ namespace AccAOI ...@@ -232,7 +237,7 @@ namespace AccAOI
} }
else else
{ {
currProjectFileName = fileName; currProjectFileName = fileName;
} }
ShowPorject(); ShowPorject();
...@@ -290,7 +295,7 @@ namespace AccAOI ...@@ -290,7 +295,7 @@ namespace AccAOI
string text = comType.Text; string text = comType.Text;
CloseCurrAoi(); CloseCurrAoi();
AoiMethod methodInfo = ControlUtil.GetMethod(text); AoiMethod methodInfo = ControlUtil.GetMethod(text);
methodInfo.MethodName = Project.methodMap.Values.Count.ToString().PadLeft(2, '0') + "_" + text; methodInfo.MethodName = Project.methodMap.Values.Count.ToString().PadLeft(2, '0') + "_" + text;
Project.methodMap.Add(methodInfo.MethodName, methodInfo); Project.methodMap.Add(methodInfo.MethodName, methodInfo);
...@@ -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;
...@@ -331,15 +336,15 @@ namespace AccAOI ...@@ -331,15 +336,15 @@ namespace AccAOI
imageBox1.SelectionRegion = method.RoiPath; imageBox1.SelectionRegion = method.RoiPath;
//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();
...@@ -356,7 +361,7 @@ namespace AccAOI ...@@ -356,7 +361,7 @@ namespace AccAOI
if (aoiControl != null) if (aoiControl != null)
{ {
if (aoiControl.Visible) if (aoiControl.Visible)
{ {
aoiControl.Close(); aoiControl.Close();
} }
aoiControl.Dispose(); aoiControl.Dispose();
...@@ -366,7 +371,7 @@ namespace AccAOI ...@@ -366,7 +371,7 @@ namespace AccAOI
private void ShowPorject() private void ShowPorject()
{ {
if (Project != null) if (Project != null)
{ {
CloseCurrAoi(); CloseCurrAoi();
aoiList.ItemClear(); aoiList.ItemClear();
BaseImg = Project.standardImage; BaseImg = Project.standardImage;
...@@ -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))
...@@ -433,15 +439,16 @@ namespace AccAOI ...@@ -433,15 +439,16 @@ namespace AccAOI
{ {
return; return;
} }
currPath = imageBox1.SelectionRegion; currPath = imageBox1.SelectionRegion;
aoiControl.SetCurrPath( currPath); aoiControl.SetCurrPath(currPath);
}catch(Exception ex) }
catch (Exception ex)
{ {
} }
} }
private void btnExcute_Click(object sender, EventArgs e) private void btnExcute_Click(object sender, EventArgs e)
{ {
SaveCurrAoi(); SaveCurrAoi();
...@@ -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))
...@@ -534,7 +541,7 @@ namespace AccAOI ...@@ -534,7 +541,7 @@ namespace AccAOI
string fileName = openDialog.FileName; string fileName = openDialog.FileName;
//读取图片内容 //读取图片内容
// TestImage = (Image)Image.FromFile(fileName).Clone(); // TestImage = (Image)Image.FromFile(fileName).Clone();
Image file = (Image)Image.FromFile(fileName); Image file = (Image)Image.FromFile(fileName);
TestImage = new Bitmap(file); TestImage = new Bitmap(file);
file.Dispose(); file.Dispose();
...@@ -550,7 +557,7 @@ namespace AccAOI ...@@ -550,7 +557,7 @@ namespace AccAOI
testImageBox1.Size = imageBox1.Size; testImageBox1.Size = imageBox1.Size;
testImageBox1.Location = imageBox1.Location; testImageBox1.Location = imageBox1.Location;
testImageBox1.Visible = false; testImageBox1.Visible = false;
} }
private void flatButton1_Click(object sender, EventArgs e) private void flatButton1_Click(object sender, EventArgs e)
...@@ -561,17 +568,37 @@ namespace AccAOI ...@@ -561,17 +568,37 @@ namespace AccAOI
MessageBox.Show("清先选择相机"); MessageBox.Show("清先选择相机");
return; return;
} }
Bitmap img = CameraManager.GetCamerImage(camera);
if (img != null) string filePath = Application.StartupPath + @"\aimage\";
string fileName = @"\test.bmp";
using (Bitmap img = CameraManager.GetCamerImage(camera))
{ {
//读取图片内容 if (img != null)
TestImage = (Image)img.Clone();
testImageBox1.Image = TestImage;
if (testImageBox1.Visible.Equals(false))
{ {
btnImageChange_Click(null, 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();
//读取图片内容
testImageBox1.Image = TestImage;
if (testImageBox1.Visible.Equals(false))
{
btnImageChange_Click(null, null);
}
}
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!