| | |
| | | using HalconDotNet; |
| | | using Sunny.UI.Win32; |
| | | using System.Diagnostics; |
| | | |
| | | namespace LB_VisionControl |
| | |
| | | /// </summary> |
| | | public bool bAutoSize = true; |
| | | |
| | | private HImage _hImage = null; |
| | | private HObject _hImage = null; |
| | | /// <summary> |
| | | /// 显示图片(异步) |
| | | /// </summary> |
| | | public HImage hImage |
| | | public HObject hImage |
| | | { |
| | | get |
| | | { |
| | |
| | | /// <param name="ho_image"></param> |
| | | /// <param name="hWindow"></param> |
| | | /// <param name="autoSize"></param> |
| | | public async void ShowHoImageAsync(HImage ho_image, HWindow hWindow, bool autoSize = true) |
| | | public async void ShowHoImageAsync(HObject ho_image, HWindow hWindow, bool autoSize = true) |
| | | { |
| | | if (ho_image == null || !ho_image.IsInitialized()) |
| | | hWindow.ClearWindow(); |
| | | HOperatorSet.ClearWindow(hWindow); |
| | | else |
| | | await ShowImageAsync(hWindow, ho_image, autoSize); |
| | | } |
| | |
| | | /// </summary> |
| | | /// <param name="ho_image"></param> |
| | | /// <param name="autoSize"></param> |
| | | public void ShowHoImage(HImage ho_image, bool autoSize = true) |
| | | public void ShowHoImage(HObject ho_image, bool autoSize = true) |
| | | { |
| | | _hImage = ho_image; |
| | | hWindowControl.HalconWindow.ClearWindow(); |
| | | HOperatorSet.ClearWindow(hWindowControl.HalconWindow); |
| | | |
| | | if (ho_image == null) |
| | | return; |
| | |
| | | return; |
| | | } |
| | | |
| | | private async Task<bool> ShowImageAsync(HWindow hWindow, HImage ho_image, bool autoSize = true) |
| | | private async Task<bool> ShowImageAsync(HWindow hWindow, HObject ho_image, bool autoSize = true) |
| | | { |
| | | return await Task.Run(() => |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | hWindow.ClearWindow(); |
| | | HOperatorSet.ClearWindow(hWindow); |
| | | } |
| | | catch { return false; } |
| | | return true; |
| | |
| | | |
| | | try |
| | | { |
| | | hWindow.ClearWindow(); |
| | | HOperatorSet.ClearWindow(hWindow); |
| | | |
| | | if (autoSize) |
| | | { |
| | | ho_image.GetImageSize(out HTuple imgWidth, out HTuple imgHeight); |
| | | HOperatorSet.GetImageSize(ho_image, out HTuple imgWidth, out HTuple imgHeight); |
| | | if (imgWidth.Length > 0) |
| | | { |
| | | hWindow.GetWindowExtents(out int winRow, out int winCol, out int winWidth, out int winHeight); |
| | |
| | | } |
| | | } |
| | | |
| | | hWindow.DispObj(ho_image); |
| | | HOperatorSet.DispObj(ho_image, hWindow); |
| | | } |
| | | catch { return false; } |
| | | return true; |
| | |
| | | try |
| | | { |
| | | if (ho_object != null && ho_object.IsInitialized()) |
| | | this.hWindowControl.HalconWindow.DispObj(ho_object); |
| | | HOperatorSet.DispObj(ho_object, this.hWindowControl.HalconWindow); |
| | | } |
| | | catch { } |
| | | } |
| | |
| | | if (ho_object != null && ho_object.IsInitialized()) |
| | | { |
| | | SetColor(color); |
| | | this.hWindowControl.HalconWindow.DispObj(ho_object); |
| | | HOperatorSet.DispObj(ho_object, this.hWindowControl.HalconWindow); |
| | | } |
| | | } |
| | | catch { } |
| | |
| | | { |
| | | string color = result ? "green" : "red"; |
| | | SetColor(color); |
| | | this.hWindowControl.HalconWindow.DispObj(ho_object); |
| | | HOperatorSet.DispObj(ho_object, this.hWindowControl.HalconWindow); |
| | | } |
| | | } |
| | | catch { } |
| | |
| | | |
| | | if (this.color != color) |
| | | { |
| | | this.hWindowControl.HalconWindow.SetColor( color); |
| | | HOperatorSet.SetColor(this.hWindowControl.HalconWindow, color); |
| | | this.color = color; |
| | | } |
| | | } |