可以完整输出一段代码吗
时间: 2023-07-31 22:10:47 浏览: 113
好的,以下是一个完整的示例代码,它可以提取VisionPro中CogToolBlockEditV21控件中的图像,并将其输出到CogRecordDisplay控件上:
```csharp
using System;
using System.Drawing;
using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.CogDisplay;
namespace VisionProTutorial
{
public partial class Form1 : Form
{
private CogToolBlockEditV21 cogToolBlockEditV21;
private CogRecordDisplay cogRecordDisplay1;
public Form1()
{
InitializeComponent();
// 创建CogToolBlockEditV21控件并设置工具块
cogToolBlockEditV21 = new CogToolBlockEditV21();
cogToolBlockEditV21.Subject = new CogToolBlock();
cogToolBlockEditV21.Subject.Tools.Add(new CogImageFileTool(), "ImageFileTool");
cogToolBlockEditV21.Subject.Inputs["InputImage"].Value = new CogImage8Grey(640, 480);
cogToolBlockEditV21.Subject.Outputs["OutputImage"].Value = new CogImage8Grey(640, 480);
cogToolBlockEditV21.Location = new Point(12, 12);
cogToolBlockEditV21.Size = new Size(320, 240);
this.Controls.Add(cogToolBlockEditV21);
// 创建CogRecordDisplay控件并设置显示模式
cogRecordDisplay1 = new CogRecordDisplay();
cogRecordDisplay1.Location = new Point(12, 258);
cogRecordDisplay1.Size = new Size(640, 480);
cogRecordDisplay1.Dock = DockStyle.Fill;
cogRecordDisplay1.HorizontalScrollBar = true;
cogRecordDisplay1.VerticalScrollBar = true;
cogRecordDisplay1.MouseWheelMode = CogDisplayMouseWheelModeConstants.Zoom1;
cogRecordDisplay1.InteractiveGraphics = true;
this.Controls.Add(cogRecordDisplay1);
// 显示输入图像
ICogImage inputImage = cogToolBlockEditV21.Subject.Inputs["InputImage"].Value as ICogImage;
cogRecordDisplay1.Image = inputImage.ToBitmap();
cogRecordDisplay1.Fit(True);
cogRecordDisplay1.StaticGraphics.Add(cogToolBlockEditV21, "ToolBlock");
}
}
}
```
这个示例代码创建了一个窗体,其中包含一个`CogToolBlockEditV21`控件和一个`CogRecordDisplay`控件。`CogToolBlockEditV21`控件中有一个`CogImageFileTool`工具块,它可以从文件中加载图像。当窗体加载时,代码会将输入图像显示在`CogRecordDisplay`控件中,并在图像上叠加`CogToolBlockEditV21`控件显示的工具块边框。
阅读全文