From fec341de45f4b3fd1825807f0b3261143fa13caa Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期一, 29 十二月 2025 17:03:45 +0800
Subject: [PATCH] 修复部分显示工具为面向对象。
---
LB_SmartVision/ProcessRun/ProcessContext.cs | 48 +++++++++++++++++++++++++++---------------------
1 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/LB_SmartVision/ProcessRun/ProcessContext.cs b/LB_SmartVision/ProcessRun/ProcessContext.cs
index ff803a2..79d4ada 100644
--- a/LB_SmartVision/ProcessRun/ProcessContext.cs
+++ b/LB_SmartVision/ProcessRun/ProcessContext.cs
@@ -301,7 +301,7 @@
return res;
}
- public bool GetImage(Layout layout, out HImage InputImage, out HObject RecordImage)
+ public bool GetImage(Layout layout, out HImage InputImage, out HImage RecordImage)
{
InputImage = null; RecordImage = null;
try
@@ -337,9 +337,9 @@
else if (o_InputImage != null && o_InputImage is Bitmap)
{
//灏哅at杞崲涓篐Object
- using (HImage ho_RecordImage = TAlgorithm.Bitmap2HObject((Bitmap)o_InputImage))
+ using (HImage ho_RecordImage = TAlgorithm.Bitmap2HImage((Bitmap)o_InputImage))
{
- if (ho_RecordImage != null)
+ if (ho_RecordImage != null && ho_RecordImage.Key != IntPtr.Zero)
{
InputImage = ho_RecordImage.Clone();
}
@@ -348,16 +348,16 @@
else if (o_InputImage != null && o_InputImage is Mat)
{
//灏哅at杞崲涓篐Object
- using (HImage ho_RecordImage = TAlgorithm.Mat2HObject((Mat)o_InputImage))
+ using (HImage ho_RecordImage = TAlgorithm.Mat2HImage((Mat)o_InputImage))
{
- if (ho_RecordImage != null)
+ if (ho_RecordImage != null && ho_RecordImage.Key != IntPtr.Zero)
{
InputImage = ho_RecordImage.Clone();
}
}
}
- if (InputImage != null && InputImage.IsInitialized())
+ if (InputImage != null && InputImage.Key != IntPtr.Zero && InputImage.IsInitialized())
{
InputImage.GetImageSize(out ho_ImageWidth, out ho_ImageHeight);
@@ -387,11 +387,13 @@
if (dicContext.ContainsKey(IndexProcessName))
{
- ObjectRecord objectRecord1 = ((IProcess)dicContext[IndexProcessName]).Record;
- if (objectRecord1 != null)
+ using (ObjectRecord objectRecord1 = ((IProcess)dicContext[IndexProcessName]).Record)
{
- objectRecord1.Display(hWindowControl.HalconWindow);
- objectRecord1.Dispose();
+ if (objectRecord1 != null)
+ {
+ objectRecord1.Display(hWindowControl.HalconWindow);
+ objectRecord1.Dispose();
+ }
}
}
}
@@ -405,11 +407,13 @@
if (dicContext.ContainsKey(IndexProcessName))
{
- ObjectRecord objectRecord2 = ((IProcess)dicContext[IndexProcessName]).Record;
- if (objectRecord2 != null)
+ using (ObjectRecord objectRecord2 = ((IProcess)dicContext[IndexProcessName]).Record)
{
- objectRecord2.Display(hWindowControl.HalconWindow);
- objectRecord2.Dispose();
+ if (objectRecord2 != null)
+ {
+ objectRecord2.Display(hWindowControl.HalconWindow);
+ objectRecord2.Dispose();
+ }
}
}
}
@@ -423,11 +427,13 @@
if (dicContext.ContainsKey(IndexProcessName))
{
- ObjectRecord objectRecord3 = ((IProcess)dicContext[IndexProcessName]).Record;
- if (objectRecord3 != null)
+ using (ObjectRecord objectRecord3 = ((IProcess)dicContext[IndexProcessName]).Record)
{
- objectRecord3.Display(hWindowControl.HalconWindow);
- objectRecord3.Dispose();
+ if (objectRecord3 != null)
+ {
+ objectRecord3.Display(hWindowControl.HalconWindow);
+ objectRecord3.Dispose();
+ }
}
}
}
@@ -435,13 +441,13 @@
if (Result)
{
Msg = "杩愯鎴愬姛";
- HOperatorSet.SetColor(hWindowControl.HalconWindow, "green");
+ hWindowControl.HalconWindow.SetColor("green");
}
else
- HOperatorSet.SetColor(hWindowControl.HalconWindow, "red");
+ hWindowControl.HalconWindow.SetColor("red");
TAlgorithm.DispMsg(Msg, hWindowControl.HalconWindow, Result ? "green" : "red", 0, 0);
- HOperatorSet.DumpWindowImage(out RecordImage, hWindowControl.HalconWindow);
+ RecordImage = hWindowControl.HalconWindow.DumpWindowImage();
#endregion
return true;
--
Gitblit v1.9.3