[VM Service Manager] VM4.x Operator SDK Development_3.4 Control Embedding Class

3.4.1 Image storage: how to save images

Description
Environment: MVDAlgrithm SDK3.4 and above + VS2013 and above
Phenomenon: how to store images in operator SDK development.
Answer
Call SaveImage (picture storage), take saving the picture to the E disk as an example, the sample code is as follows, in which it is necessary to determine that the folder in the path has been created.

1.	C#
2.	
3.	string imageName="a";
4.	MVD_FILE_FORMAT ms=MVD_FILE_FORMAT.MVD_FILE_BMP;//图片格式
5.	//保存原图
6.	runImage.SaveImage(“E:\\”+imageName+”_origin.bmp”);
7.	//保存渲染图,参数分别为图片路径,图片格式,图片质量(0-100)
8.	mvdRenderActivex1.SaveImage(“E:\\”+imageName+”_render.bmp”,ms,100,MVD_SAVE_TYPE.MVD_SAVE_RESULT_IMAGE);

The root cause of the problem
is not familiar with the use of related interfaces.

3.4.2 Auxiliary crosshair: the method of adding auxiliary crosshair to the image

Description
Environment: MVDAlgrithm SDK3.4 and above + VS2013 and above
Phenomenon: Some users hope to display auxiliary crosshairs on the image when developing with Operator SDK.
Answer
The method for the operator SDK to display the auxiliary crosshair on the image is as follows:

1.	c#
2.	 
3.	CMvdLineSegmentF line1 = new CMvdLineSegmentF(new MVD_POINT_F(mvdimage.Width/2, 0),new MVD_POINT_F(mvdimage.Width / 2, mvdimage.Height ));//定义线段
4.	CMvdLineSegmentF line2 = new CMvdLineSegmentF(new MVD_POINT_F(0, mvdimage.Height/2),new MVD_POINT_F(mvdimage.Width, mvdimage.Height/2));//定义线段
5.	line1.BorderStyle = MVD_DASH_STYLE.MvDashStyleDashDot;//设置线型
6.	line1.BorderColor = new MVD_COLOR(250, 0, 0);//设置线的颜色
7.	line2.BorderStyle = MVD_DASH_STYLE.MvDashStyleDashDot;//设置线型
8.	line2.BorderColor = new MVD_COLOR(250, 0, 0);//设置线的颜色
9.	mvdRenderActivex1.AddShape(line1);//添加线段1
10.	mvdRenderActivex1.AddShape(line2);//添加线段2
11.	mvdRenderActivex1.Display();//渲染

The root cause of the problem
I do not understand the relevant interfaces of the operator SDK

3.4.3 Control call: method of using Winform control in WPF

Description
Environment: MVDAlgrithm SDK3.4 and above + VS2013 and above
Phenomenon: How do users use the packaged Winform template matching and other controls during the development of the operator SDK?
answer

  1. First add a reference to the following two dll files: WindowsFormsIntegration.dll, System.Windows.Forms.dll.
    insert image description here

  2. Add a reference in the XAML file of the WPF form that will use the WinForm control. The sample code is as follows:

C# 
 
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows. Forms"
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly= WindowsFormsIntegration"
  1. In the container control of WPF, such as StackPanel, the host container of WinForm control must be added first to connect WPF and WinForm. The sample code is as follows:
C# XAML
 
<StackPanel>
	<wfi:WindowsFormsHost x:Name="host" Margin="0,0,0,0" />      
</StackPanel>"
  1. Define UserControl1 in code user= new UserControl1 (); Don't forget to add reference here. UserControl1 is a custom Winform user control for storing controls. Then put the control into WindowsFormsHost, the sample code is as follows:
C# .CS
 
UserControl1 user= new UserControl1 ();
this.host.Child = user; //使XML文件中的host中的内容为用户控件user
  1. For example, to call the rendering control in WPF in the operator SDK, add the rendering control dll, and the sample code is as follows.
    insert image description here
    insert image description here

The root cause
of the problem I don't know how to use custom Winform controls in WPF.

3.4.4 Graphics change event: the implementation method of the graphics change event on the rendering control

Description
Environment: MVDAlgrithm SDK3.4 and above + VS2013 and above
Phenomenon: How to use graph change event in operator SDK?
Answer
The operator SDK supports five types of shape change events, namely shape addition event (MVD_SHAPE_ADDED), shape deletion event (MVD_SHAPE_DELETED), shape editing event (MVD_SHAPE_EDITED), shape selection event (MVD_SHAPE_SELECTED) and undefined event (MVD_SHAPE_UNDEFINE ). Let's take the most commonly used graphics adding event as an example, the code is as follows:

C#  
//注册图形改变事件
this.mvdRenderActivex1.MVDShapeChangedEvent += mvdRenderActivex1_MVDShapeChangedEvent;

//实现图形改变事件
private void mvdRenderActivex1_MVDShapeChangedEvent(VisionDesigner.MVDRenderActivex.MVD_SHAPE_EVENT_TYPE enEventType, VisionDesigner.MVD_SHAPE_TYPE enShapeType, VisionDesigner.CMvdShape cShapeObj)
{
    if (MVDRenderActivex.MVD_SHAPE_EVENT_TYPE.MVD_SHAPE_ADDED == enEventType)
    {
        //添加图形时具体执行的逻辑代码
    }
}

Root cause of the problem
Not familiar with how graphics change events are implemented.

3.4.5 Mouse event: the method to realize the mouse event on the rendering control

Description
Environment: MVDAlgrithm SDK3.4 and above + VS2013 and above
Phenomenon: During the development of Operator SDK, how does the rendering control trigger mouse events
Answer
In the development process of Operator SDK, 7 types of mouse events are supported. Cut left mouse button down (LButtonDown), left mouse button up (LButtonUp), right mouse button down (RButtonDown), right mouse button up (RButtonUp), left mouse button double-click (LButtonDblClk), mouse move (MouseMove), mouse Wheel (MouseWheel). It is more commonly used to display image coordinates and pixel values ​​according to the position of the mouse on the control. The code is as follows:

C#
//在初始化的时候,设置交互模式,标准交互+自定义交互(StandardAndCustom)
mvdRenderActivex1.SetConfiguration((uint)MVD_RENDER_PARAM_KEY.MvdRenderInteractType, (int)MVDRenderInteractType.StandardAndCustom);

//事件注册,打开渲染控件属性,选择相应事件可以自动生成
//用户想要实现自定义交互需通过SetConfiguration接口启用自定义交互
//用户可根据enMouseEventType判断鼠标事件类型,编写对应的响应函数
//示例:实时显示鼠标所在位置的图像坐标和像素值
private void mvdRenderActivex1_MVDMouseEvent(MVDMouseEventType enMouseEventType, int nPointX, int nPointY, short nZDelta)
{    
    try
    {
        //窗口坐标转图像坐标
        float fImgX = 0.0f, fImgY = 0.0f;
        mvdRenderActivex1.TransformCoordinate(nPointX, nPointY, ref fImgX, ref fImgY, MVDCoordTransType.Wnd2Img);

        //获取像素信息显示
        do
        {
            if (false == _ImageLoaded)
            {
                break;
            }

            int nImagePointX = (int)fImgX;
            int nImagePointY = (int)fImgY;
            int nWidth = (int)_InputImage.Width;
            int nHeight = (int)_InputImage.Height;
            if (nImagePointX < 0 || nImagePointX >= nWidth
                || nImagePointY < 0 || nImagePointY >= nHeight)
            {
                break;
            }

            string pixelInfo = string.Empty;
            List<byte> pixelValue = _InputImage.GetPixel(nImagePointX, nImagePointY);
            MVD_PIXEL_FORMAT enPixelFormat = _InputImage.PixelFormat;
            if (MVD_PIXEL_FORMAT.MVD_PIXEL_MONO_08 == enPixelFormat)
            {
                pixelInfo = string.Format("X:{0:D4} Y:{1:D4} | R:{2:D3} G:{3:D3} B:{4:D3}", nImagePointX, nImagePointY, pixelValue[0], pixelValue[0], pixelValue[0]);
            }
            else if (MVD_PIXEL_FORMAT.MVD_PIXEL_RGB_RGB24_C3 == enPixelFormat)
            {
                pixelInfo = string.Format("X:{0:D4} Y:{1:D4} | R:{2:D3} G:{3:D3} B:{4:D3}", nImagePointX, nImagePointY, pixelValue[0], pixelValue[1], pixelValue[2]);
            }
            else
            {
                throw new MvdException(MVD_MODULE_TYPE.MVD_MODUL_APP, MVD_ERROR_CODE.MVD_E_SUPPORT, "Unsupported pixel format.");
            }
            this.tbPixelInfo.Text = pixelInfo;
        } while (false);
    }
    catch (MvdException ex)
    {
        this.rtbInfoMessage.Text += String.Format("Fail to respond to mouse event! Module : {0}, ErrorCode : 0x{1}, Message : {2}.\r\n", ex.ModuleType.ToString(), ex.ErrorCode.ToString("X"), ex.Message);
    }
    catch (System.Exception ex)
    {
        this.rtbInfoMessage.Text += String.Format("Fail to respond to mouse event! Message : {0}, StackTrace : {1}.\r\n", ex.Message, ex.StackTrace);
    }
}

The root cause of the problem
is not familiar with the implementation of mouse events

Guess you like

Origin blog.csdn.net/MVExpert/article/details/130409640