显示现场视频: 图形叠加: 可移动坐标准心

使用IC Imaging Control在视频上加入可移动坐标准心。
语言:.NET C#/Visual Basic
版本:3.0.3
发布于:2005年4月7日
作者:IC Imaging Control 技术支持部
系统要求:IC Imaging Control >2.1
由WDM数据流类驱动程序驱动的相机、视频转换器或图像采集卡

示例程序窗口如图所示:

The dialog window of the sample application.

程序开始后首先调用对话框(.ShowDeviceSettingsDialog)用于选择设备。 在Form_Load()结尾处 .LiveStart将显示设备传来的现场视频。 准备工作有两步:第一,开启叠加模式(.OverlayBitmap.Enable)。第二,将dragging状态设为False, 该变量将被用于指示鼠标左键是否处于按下状态。

[C#]
bool bDragging = false;

private void Form1_Load(object sender, System.EventArgs e)
{
    icImagingControl1.ShowDeviceSettingsDialog();

    if( !icImagingControl1.DeviceValid )
    {
        Close();
        return;
    }

    icImagingControl1.OverlayBitmap.Enable = true;
    icImagingControl1.OverlayBitmap.ColorMode = TIS.Imaging.OverlayColorModes.Color;
    icImagingControl1.LiveStart();
}

坐标准心由两条红色线段和一副蓝色坐标值构成。.OverlayBitmap.DrawLine用于划线,.OverlayBitmap.DrawText生成坐标:

[C#]
private void DrawCrosshairs( int x, int y )
{
    icImagingControl1.OverlayBitmap.DrawLine( Color.Red, x, y-10, x, y+10 );
    icImagingControl1.OverlayBitmap.DrawLine( Color.Red, x-10, y, x+10, y );
    icImagingControl1.OverlayBitmap.DrawText( Color.Blue, x+3, y+2, x.ToString() + "," + y.ToString() );
}

决定准心位置的有两个因素:鼠标的运动及其按键状态。 用户点击画面,程序将删除旧的坐标点,给叠加层bitmap填入透明色.DropOutColor。DisplayCrosshairs XPos, YPos 将为鼠标画出新的准心:

[C#]
private void icImagingControl1_MouseDown(object sender, TIS.Imaging.ICImagingControl.MouseEventArgs e)
{
    if( (e.ModifierKeys & Keys.Shift) == 0 )
    {
        icImagingControl1.OverlayBitmap.Fill( icImagingControl1.OverlayBitmap.DropOutColor );
    }

    DrawCrosshairs( e.x, e.y );

    bDragging = true;
}

用户按住左键移动鼠标时,程序将删除旧的坐标点,给叠加层bitmap填入透明色.DropOutColor. DisplayCrosshairs XPos, YPos将为鼠标画出新的准心:

[C#]
private void icImagingControl1_MouseMove(object sender, TIS.Imaging.ICImagingControl.MouseEventArgs e)
{
    if( bDragging )
    {
        if( (e.ModifierKeys & Keys.Shift) == 0 )
        {
            icImagingControl1.OverlayBitmap.Fill( icImagingControl1.OverlayBitmap.DropOutColor );
        }

        DrawCrosshairs( e.x, e.y );
    }
}

放开鼠标将把状态变量dragging重设为False:

[C#]
private void icImagingControl1_MouseUp(object sender, TIS.Imaging.ICImagingControl.MouseEventArgs e)
{
    bDragging = false;
}

相关源代码示例

责任声明
IC Imaging Control 源代码库中的所有代码均只用于教学目的,The Imaging Source Europe GmbH 作为IC Imaging Control的开发制造商,不对任何由于使用本文或其中源代码所产生的后果承担责任。

该网站为The Imaging Source网络的一部分。其它的站点包括 公司, Imaging, 天文相机, Astronomy Cameras Blog, Blog caméras d'astronomie, 天文相机有奖竞答, TX Text Control, LiveDocx, phpLiveDocxForum.