程序界面通过 CogRecordDisplay 控件显示视觉运行结果图像。
按指定图像显示,代码如下:
using System; using System.Windows.Forms; using Cognex.VisionPro; using Cognex.VisionPro.ToolBlock; /// <summary> /// 显示指定视觉图像 /// </summary> /// <param name="cogdisplay">显示控件</param> /// <param name="cogImage">显示图像</param> public void ShowDisplayByImage(CogRecordDisplay cogDisplay, CogImage8Grey cogImage) { try { cogDisplay.Image = null; cogDisplay.StaticGraphics.Clear(); cogDisplay.InteractiveGraphics.Clear(); cogDisplay.Image = cogImage; cogDisplay.AutoFit = true; } catch (Exception ex) { MessageBox.Show("图像显示失败!"); } }
按指定VisionPro 工具包 CogToolBlock 内的工具序号显示该工具结果图像,代码如下:
using System; using System.Windows.Forms; using System.IO; using Cognex.VisionPro; using Cognex.VisionPro.ToolBlock; /// <summary> /// 显示工具图像 /// </summary> /// <param name="CogTB">显示工具文件</param> /// <param name="cogdisplay">显示控件名称</param> /// <param name="ShowSubRecordsIndex">视觉工具序号</param> public void ShowDisplayByTool(CogRecordDisplay cogDisplay, CogToolBlock CogTB, int ShowSubRecordsIndex) { try { cogDisplay.Image = null; cogDisplay.StaticGraphics.Clear(); cogDisplay.InteractiveGraphics.Clear(); if (CogTB != null) { cogDisplay.Record = CogTB.CreateLastRunRecord().SubRecords[ShowSubRecordsIndex];//按序指定工具图像 //cogdisplay.Record = CogTB.CreateLastRunRecord();//最后一张 cogDisplay.AutoFit = true; cogDisplay.Fit(); } else { MessageBox.Show("显示工具文件不存在!"); } } catch (Exception ex) { MessageBox.Show("图像显示失败!"); } }