在 Windows 上的 Visual Studio 中构建 C# "Zivid Hello World" 应用程序
本教程介绍如何在 Visual Studio 2022 中使用 Zivid 创建和开发 C# 应用程序。请注意,对于其他版本的 Visual Studio,步骤可能会略有不同。
要求
备注
Zivid 使用的 .NET framework 版本为 4.5.2。有关更多信息,请参阅 .NET framework 版本 。
说明
创建一个新项目
运行 Visual Studio,然后单击 Create new project ,或 File → New → Project... 。选择 Visual C# 的控制台应用程序。
然后,添加您的项目名称、位置和 .NET 版本。在本教程中,我们将使用以下文件名和位置:
位置  | 
  | 
C# 文件名  | 
  | 
.NET 版本  | 
  | 
添加主C#代码
将 ZividHelloWorld.cs 中的代码替换为以下代码片段:
using System;
namespace ZividHelloWorld
{
    class ZividHelloWorld
    {
        static int Main()
        {
            try
            {
                var zivid = new Zivid.NET.Application();
                Console.WriteLine("Hello World!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                return 1;
            }
            return 0;
        }
    }
}
添加对Zivid .NET API的引用
我们必须添加对 Zivid .NET API 的引用才能运行代码示例。在解决方案资源管理器中右键单击您的项目,然后单击 Add → Project Reference... → Browse 。导航到 C:Program FilesZividbin 并添加 ZividCoreNET.dll 和 ZividVisualizationNET.dll 。
选择正确的platform target
再次右键单击您的项目,然后单击 Properties 。在 Build → General 下,将 Platform target 更改为 x64 。
添加构建后事件命令行代码
在同一个 Build 页面中,在 Events 下,将以下代码块添加到 Post-build event 事件命令行:
if $(ConfigurationName) == Debug GOTO Debug
if $(ConfigurationName) == Release GOTO Release
goto Error
:Debug
xcopy "$(ZIVID_INSTALL_FOLDER)\bin_debug\*.dll" "$(TargetDir)" /Y
exit /B 0
:Release
xcopy "$(ZIVID_INSTALL_FOLDER)\bin\*.dll" "$(TargetDir)" /Y
exit /B 0
:Error
echo Unsupported config
exit /B 1
运行程序
现在我们已经设置并配置了所有内容。按 F5 键运行该程序。
要继续使用Zivid 和 C#进行开发,请查 看 Zivid .NET API reference 和下一页的教程 使用Visual Studio构建C#示例 。
版本历史
SDK  | 
变更  | 
|---|---|
2.12.0  | 
移除了对 Visual Studio 2017 的支持。  |