Commit 0fdda9d7 LN

1

1 个父辈 b3c9937e
......@@ -31,28 +31,34 @@ namespace AOI
/// <returns></returns>
public GraphicsPath GetSearchPath()
{
if(RoiPath != null && SearchPathZoom > 0)
try
{
GraphicsPath SearchPath = new GraphicsPath(RoiPath.PathPoints, RoiPath.PathTypes);
Matrix matrix = new Matrix();
matrix.Scale(SearchPathZoom, SearchPathZoom);
SearchPath.Transform(matrix);
if (RoiPath != null && SearchPathZoom > 0)
{
GraphicsPath SearchPath = new GraphicsPath(RoiPath.PathPoints, RoiPath.PathTypes);
Matrix matrix = new Matrix();
matrix.Scale(SearchPathZoom, SearchPathZoom);
SearchPath.Transform(matrix);
var oldBounds = this.RoiPath.GetBounds();
var newBounds = SearchPath.GetBounds();
var oldCenterX = oldBounds.X + oldBounds.Width / 2;
var oldCenterY = oldBounds.Y + oldBounds.Height / 2;
var oldBounds = this.RoiPath.GetBounds();
var newBounds = SearchPath.GetBounds();
var oldCenterX = oldBounds.X + oldBounds.Width / 2;
var oldCenterY = oldBounds.Y + oldBounds.Height / 2;
var newCenterX = newBounds.X + newBounds.Width / 2;
var newCenterY = newBounds.Y + newBounds.Height / 2;
var newCenterX = newBounds.X + newBounds.Width / 2;
var newCenterY = newBounds.Y + newBounds.Height / 2;
matrix.Reset();
matrix.Translate(oldCenterX - newCenterX, oldCenterY - newCenterY);
SearchPath.Transform(matrix);
matrix.Reset();
matrix.Translate(oldCenterX - newCenterX, oldCenterY - newCenterY);
SearchPath.Transform(matrix);
return SearchPath;
}
return RoiPath;
return SearchPath;
}
return RoiPath;
}catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}return null;
}
/// <summary>
......
......@@ -35,17 +35,17 @@ namespace AccAOI
this.WindowState = FormWindowState.Maximized;
if (!programPath.Equals(""))
{
// BaseImg = image;
// Project = new AoiProject(image);
// BaseImg = image;
// Project = new AoiProject(image);
string result = "";
Project= AoiProject.Load(programPath,out result);
Project = AoiProject.Load(programPath, out result);
if (!result.Equals(""))
{
MessageBox.Show("加载项目" + programPath + "失败:\r\n" + result);
}
else
{
currProjectFileName= programPath;
currProjectFileName = programPath;
}
}
if (image != null)
......@@ -53,7 +53,7 @@ namespace AccAOI
if (Project != null)
{
Project.standardImage = image;
}
}
}
DefaultPath = defaultPath;
......@@ -74,8 +74,8 @@ namespace AccAOI
file.Dispose();
imageBox1.Image = BaseImg;
}
foreach (string str in CameraManager.hikNameList)
{
cmbCameraList.ItemAdd(str);
......@@ -86,9 +86,9 @@ namespace AccAOI
}
if (Project != null)
{
ShowPorject();
}
}
ShowPorject();
}
}
private void btnOpenImage_Click(object sender, EventArgs e)
{
......@@ -96,7 +96,7 @@ namespace AccAOI
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.DefaultExt = "png";
//openDialog.DefaultExt = "png";
System.Windows.Forms.DialogResult result = openDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel)
......@@ -131,9 +131,9 @@ namespace AccAOI
MessageBox.Show("清先选择相机");
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 fileName = @"\test.bmp";
string fileName = @"\base.bmp";
using (Bitmap img = CameraManager.GetCamerImage(camera))
{
if (img != null)
......@@ -145,12 +145,17 @@ namespace AccAOI
}
img.Save(filePath + fileName, ImageFormat.Bmp);
}
else
{
MessageBox.Show("获取图片失败");
return;
}
}
GC.Collect();
Image file = (Image)Image.FromFile(filePath + fileName);
BaseImg = new Bitmap(file);
file.Dispose();
// BaseImg = (Image)Image.FromFile(filePath+ file).Clone();
// BaseImg = (Image)Image.FromFile(filePath+ file).Clone();
//读取图片内容
//BaseImg = (Image)img.Clone();
if (Project != null)
......@@ -163,7 +168,7 @@ namespace AccAOI
btnImageChange_Click(null, null);
}
}
catch(Exception ex)
catch (Exception ex)
{
Console.WriteLine("btnGetCameraImg_Click Error:" + ex.ToString());
MessageBox.Show(ex.ToString());
......@@ -200,7 +205,7 @@ namespace AccAOI
this.imageBox1.Image.Dispose();
this.imageBox1.Image = null;
}
GC.Collect();
}
else
......@@ -221,7 +226,7 @@ namespace AccAOI
{
return;
}
string fileName = openDialog.FileName;
// Project = new AoiProject(BaseImg);
string msg = "";
......@@ -232,7 +237,7 @@ namespace AccAOI
}
else
{
currProjectFileName = fileName;
currProjectFileName = fileName;
}
ShowPorject();
......@@ -290,7 +295,7 @@ namespace AccAOI
string text = comType.Text;
CloseCurrAoi();
AoiMethod methodInfo = ControlUtil.GetMethod(text);
methodInfo.MethodName = Project.methodMap.Values.Count.ToString().PadLeft(2, '0') + "_" + text;
Project.methodMap.Add(methodInfo.MethodName, methodInfo);
......@@ -318,7 +323,7 @@ namespace AccAOI
aoiControl.FormBorderStyle = FormBorderStyle.None;
aoiControl.StartPosition = FormStartPosition.CenterParent;
aoiControl.Location = new Point(0, 0);
aoiControl.BImageBox=this.imageBox1;
aoiControl.BImageBox = this.imageBox1;
aoiControl.AoiInfo = method;
aoiControl.Size = panAoi.Size;
aoiControl.TitleName = method.MethodName;
......@@ -331,15 +336,15 @@ namespace AccAOI
imageBox1.SelectionRegion = method.RoiPath;
//Image threshImage = CutImage(imageBox1.Image, currPath);
//cutImage = threshImage;
aoiControl.SetCurrPath(currPath,true);
aoiControl.SetCurrPath(currPath, true);
}
aoiControl.Show();
aoiControl.ShowAoiInfo();
}
private void SaveCurrAoi()
{
if (aoiControl != null &&aoiControl.Visible)
if (aoiControl != null && aoiControl.Visible)
{
AoiMethod method = aoiControl.GetAoiInfo();
......@@ -356,7 +361,7 @@ namespace AccAOI
if (aoiControl != null)
{
if (aoiControl.Visible)
{
{
aoiControl.Close();
}
aoiControl.Dispose();
......@@ -366,7 +371,7 @@ namespace AccAOI
private void ShowPorject()
{
if (Project != null)
{
{
CloseCurrAoi();
aoiList.ItemClear();
BaseImg = Project.standardImage;
......@@ -383,7 +388,8 @@ namespace AccAOI
{
aoiList.Index = index;
ShowAoi(Project.methodMap[key]);
}index++;
}
index++;
}
}
if (imageBox1.Visible.Equals(false))
......@@ -433,15 +439,16 @@ namespace AccAOI
{
return;
}
currPath = imageBox1.SelectionRegion;
aoiControl.SetCurrPath( currPath);
}catch(Exception ex)
currPath = imageBox1.SelectionRegion;
aoiControl.SetCurrPath(currPath);
}
catch (Exception ex)
{
}
}
}
private void btnExcute_Click(object sender, EventArgs e)
{
SaveCurrAoi();
......@@ -486,7 +493,7 @@ namespace AccAOI
}
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 (Project.methodMap.ContainsKey(aoiControl.AoiInfo.MethodName))
......@@ -534,7 +541,7 @@ namespace AccAOI
string fileName = openDialog.FileName;
//读取图片内容
// TestImage = (Image)Image.FromFile(fileName).Clone();
// TestImage = (Image)Image.FromFile(fileName).Clone();
Image file = (Image)Image.FromFile(fileName);
TestImage = new Bitmap(file);
file.Dispose();
......@@ -550,7 +557,7 @@ namespace AccAOI
testImageBox1.Size = imageBox1.Size;
testImageBox1.Location = imageBox1.Location;
testImageBox1.Visible = false;
}
private void flatButton1_Click(object sender, EventArgs e)
......@@ -561,17 +568,37 @@ namespace AccAOI
MessageBox.Show("清先选择相机");
return;
}
Bitmap img = CameraManager.GetCamerImage(camera);
if (img != null)
string filePath = Application.StartupPath + @"\aimage\";
string fileName = @"\test.bmp";
using (Bitmap img = CameraManager.GetCamerImage(camera))
{
//读取图片内容
TestImage = (Image)img.Clone();
testImageBox1.Image = TestImage;
if (testImageBox1.Visible.Equals(false))
if (img != null)
{
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!