Halcon 学习笔记(2):Halcon+WPF导入

前言

这里补充一下Halcon导入到WPF的要求

.net core 8.0

Halcon是支持.net core 8.0导入的

.net core 8.0新功能,打开文件夹和打开文件

[RelayCommand]
public void SelectFile()
{
    MsgHelper.Info("选择文件路径");
    var dialog = new Microsoft.Win32.OpenFileDialog();
    dialog.Title = "选择文件路径"; // Default file name

    // Show open file dialog box
    bool? result = dialog.ShowDialog();

    // Process open file dialog box results
    if (result == true)
    {
        // Open document
        string filename = dialog.FileName;
        MsgHelper.Success($"选择文件路径:{filename}");
    }
}

[RelayCommand]
public void SelectFolder()
{
    MsgHelper.Info("选择文件夹路径");
    var dialog = new Microsoft.Win32.OpenFolderDialog();
    dialog.Title = "选择文件夹路径"; // Default file name

    // Show open file dialog box
    bool? result = dialog.ShowDialog();

    // Process open file dialog box results
    if (result == true)
    {
        // Open document
        string filename = dialog.FolderName;
        MsgHelper.Success($"选择文件路径:{filename}");
    }
}

HSmartWindowControlWPF

System.Drawing.Common

Halcon需要系统绘制DLL,需要nuget库导入

重置拉伸

        [RelayCommand]
        public void ReadImg()
        {
            var imageUrl = "D:/workspace/program/Halcon/Images/A.png";
            MsgHelper.Info($"读取图片,图片路径{imageUrl}");
            HImage.ReadImage(imageUrl);
            HSmart.HalconWindow.DispObj(HImage);
            //图片适应阶段
            HSmart.SetFullImagePart();
        }

关闭拖拽和缩放

<!--为了防止拖拽和缩放,这里可以关掉-->
<halcon:HSmartWindowControlWPF Grid.Row="1"
                               x:Name="HSmart"
                               HMoveContent="False"
                               HZoomContent="Off"
                               HDoubleClickToFitContent="False" />

文件导出

  • HOperatorSet.WriteImage:图片导出
  • HOperatorSet.WriteShapeModel:模板导出
posted @ 2024-07-08 08:37  gclove2000  阅读(61)  评论(0编辑  收藏  举报