(十六)16位灰色图源显示
1.补充图像函数
WriteableBitmap方法参数:
- pixelWidth: 位图所需的宽度。
- pixelHeight: 位图所需的高度。
- dpiX:位图的每英寸水平点数(dpi)。
- dpiY: 位图的每英寸垂直点数(dpi)。
- pixelFormat: 位图的 System.Windows.Media.PixelFormat 格式。
- palette:位图的 System.Windows.Media.Imaging.BitmapPalette 调色板。
![image]()
Int32Rect参数:
- x: 新 System.Windows.Int32Rect 实例的 System.Windows.Int32Rect.X 坐标,用于指定矩形左上角的 x 坐标。
- y:新的 System.Windows.Int32Rect 实例的 System.Windows.Int32Rect.Y 指定矩形左上角的 Y 坐标。
- width:新的 System.Windows.Int32Rect 实例的 System.Windows.Int32Rect.Width 指定矩形的宽度。
- height:新 System.Windows.Int32Rect 实例的 System.Windows.Int32Rect.Height指定矩形高度的值。
![image]()
WritePixels参数

- Updates the pixels in the specified region of the bitmap.
更新位图指定区域内的像素。 - The rectangle of the System.Windows.Media.Imaging.WriteableBitmap to update.
要更新的 System.Windows.Media.Imaging.WriteableBitmap 的矩形。 - The input buffer used to update the bitmap.
用于更新位图的输入缓冲区。 - The size of the input buffer.
输入缓冲区的大小。 - The stride of the update region in buffer.
缓冲区中更新区域的跨距。
重载中多2个:
- destinationX: 返回缓冲区中最左边像素的目标 X 坐标。
- destinationY:返回缓冲区中最顶端像素的目标 Y 坐标。
2.16位灰色图源绑定到Image控件
定义16位灰度位图,用于WPF显示

前台显示:

运行时报错

解决

运行流程解析
-
初始化image模块时,对应的viewmodel代码执行,此时从容器中拿到IDetectorProcessModel,IDetector且实例化,detectorProcessModel订阅了图像采集接收,但此时没有采集,source数据为空。
![image]()
-
然后执行detector.Grab();--->DetectorBase基类中方法先执行
![image]()
-
NoneDetector子类中DoGrab方法执行
![image]()
-
此时开启一个持续执行的子线程(因为FPD是持续传递数据),现在开始有2个线程在运行,主线程任然是UI线程
![image]()
子线程
-
开辟非托管内存区域
![image]()
-
先执行基类构造函数再执行子类
![image]()
-
执行DetectorBase基类的函数InvokeOnGrabbed,凡是订阅图像采集事件的都响应
![image]()
-
OnGrabbed.GetInvocationList()获取全部订阅的,目前只有这一个
![image]()
item就是那个委托method
![image]()
-
new DetectorImage(image), DetectorImage用来暂存图像数据,image就是 temp=unmanagedArray.DeepClone()采集过来的图像
![image]()

-
invoke响应在DetectorReceiveManager中
![image]()
-
执行DetectorReceiveManager中写方法
![image]()
-
DoubleBuffer中,执行缓冲区切换,创建缓冲区二
![image]()
-
然后把原图像复制到缓冲区二,更改缓冲区类型和当前缓冲区
![image]()
-
缓冲区一旦改变
![image]()
-
前台页面响应,因为这是后台线程所以要通过Dispatcher来显示图片
![image]()
-
执行Gray16ImageSource中的写方法
![image]()
![image]()
11,12其实是在前台线程完成的
-
8,9,10 current变化响应结束跳出双缓存区的写方法
![image]()
-
跳出FPD图像处理模型的写方法
![image]()
-
跳出FPD图像接收服务管理器的响应事件
![image]()
-
6,7 跳出invoke方法
![image]()
-
3,4,5跳出基类的InvokeOnGrabbed
![image]()
-
非托管数据基类内存释放
![image]()
-
跳出子类RunGrab()
主线程
-
DoGrab方法执行完跳出
![image]()
-
detector.Grab()执行完跳出
![image]()
-
imageviewmodel执行完,image模块初始化完成
-
主线程继续初始化process模块
![image]()
-
全部模块初始化完执行主模块加载
![image]()
-->
![image]()
-
跳出5初始化模块的viewmodel
![image]()
结果展示

错误修改

因为探测器一直在读取,所以在关闭软件时应该关闭所有硬件

使用事件通知


还有一个错误,关闭后current为空这边

判空,空不执行



































浙公网安备 33010602011771号