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

从视频捕捉设备那里获得图像数据并存入 IC Imaging Control 的环形缓存。 当鼠标在画面中移动时,程序将显示其所指点像素的RGB色彩值。
程序开始后将首先调用一个内置对话框,用以选择一个视频设备。 具体语句为 icImagingControl1.ShowDeviceSettingsDialog。 当选择一个有效设备后,调用 icImagingControl1.LiveStart 将开启视频。 属性 icImagingControl1.LiveCaptureContinuous 自动被设置为 True。 这将使得 IC Imaging Control 连续不断地将每一帧图像复制到环形缓存中去。
.MemoryCurrentGrabberColorformat = ICRGB24 将确保图像数据格式为RGB24:
[C#] private void Form1_Load(object sender, System.EventArgs e) { icImagingControl1.ShowDeviceSettingsDialog(); if( !icImagingControl1.DeviceValid ) { Close(); return; } icImagingControl1.LiveCaptureContinuous = true; icImagingControl1.MemoryCurrentGrabberColorformat = TIS.Imaging.ICImagingControlColorformats.ICRGB24; icImagingControl1.LiveStart(); }
在鼠标移动事件处理程序中,先定义一个TIS.Imaging.ImageBuffer类型变量ib。 程序使用该变量访问最近抓取的一帧图像。 调用属性icImagingControl1.ImageActiveBuffer即可获得最近一帧图像。 为了防止图像被覆盖,可使用ib.Lock()锁住该帧图像所处的缓存单元。 示例程序还在鼠标移动事件处理程序中使用了函数GetImageColorValueRGB24(),用以完成图像处理功能。 。 鼠标移动事件处理程序的 C# 源代码如下:
[C#] private void icImagingControl1_MouseMove(object sender, TIS.Imaging.ICImagingControl.MouseEventArgs e) { lblCoords.Text = e.x + "," + e.y; TIS.Imaging.ImageBuffer ib = icImagingControl1.ImageActiveBuffer; ib.Lock(); if( e.x < ib.PixelPerLine && e.y < ib.Lines ) { byte red, green, blue; getImageColorValueRGB24( ib, e.x, e.y, out red, out green, out blue ); txtImageData.Text = string.Format( "Red\t= {0}\r\nGreen\t= {1}\r\nBlue\t= {2}", red, green, blue ); } else { txtImageData.Text = "<Outside of image>"; } ib.Unlock(); }
函数 GetImageColorValueRGB24() 用于访问图象缓存中鼠标所指的像素点。 需要注意的是,RGB24格式的图像数据的存储都是上下颠倒的。 第0行保存的是图像中最后一行的色彩值,第1行保存的是图像中倒数第二行的色彩值,如此类推。 第一列保存的是第一个象素点的蓝色分量值,第二列是绿色值,第三列是红色之。 依此类推,第四列保存的就是第二个象素点的蓝色值。 C# 源代码(可下载)中含有像素位置计算的相关语句。 具体如下:
[C#] private void getImageColorValueRGB24( TIS.Imaging.ImageBuffer ib, int x, int y, out byte red, out byte green, out byte blue ) { int indexXred = x * 3 + 2; int indexXgreen = x * 3 + 1; int indexXblue = x * 3; int indexY = ib.Lines - y - 1; red = ib[ indexXred, indexY ]; green = ib[ indexXgreen, indexY ]; blue = ib[ indexXblue, indexY ]; }
责任声明
IC Imaging Control 源代码库中的所有代码均只用于教学目的,The Imaging Source Europe GmbH 作为IC Imaging Control的开发制造商,不对任何由于使用本文或其中源代码所产生的后果承担责任。