• 大小: 1.56MB
    文件类型: .zip
    金币: 2
    下载: 3 次
    发布日期: 2023-10-15
  • 语言: C#
  • 标签: SDKCanonC#  

资源简介

基本上支持所有佳能单反,内含C#语言完整实例,直接可以运行调试。仅供学习交流。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Threading;
using EDSDKLib;

namespace ConsoleExample
{
    class Program
    {
        static SDKHandler CameraHandler;
        static bool WaitForEvent;

        static void Main(string[] args)
        {
            try
            {
                CameraHandler = new SDKHandler();
                CameraHandler.SDKobjectEvent += handler_SDKobjectEvent;
                List cameras = CameraHandler.GetCameraList();
                if (cameras.Count > 0)
                {
                    CameraHandler.OpenSession(cameras[0]);
                    Console.WriteLine(“Opened session with camera: “ + cameras[0].Info.szDeviceDescription);
                }
                else
                {
                    Console.WriteLine(“No camera found. Please plug in camera“);
                    CameraHandler.CameraAdded += handler_CameraAdded;
                    CallEvent();                    
                }

                CameraHandler.ImageSaveDirectory = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) “RemotePhoto“);
                CameraHandler.SetSetting(EDSDK.PropID_SaveTo (uint)EDSDK.EdsSaveTo.Host);

                Console.WriteLine(“Taking photo with current settings...“);
                CameraHandler.TakePhoto();

                CallEvent();
                Console.WriteLine(“Photo taken and saved“);
            }
            catch (Exception ex) { Console.WriteLine(“Error: “ + ex.Message); }
            finally
            {
                CameraHandler.CloseSession();
                CameraHandler.Dispose();
                Console.WriteLine(“Good bye! (press any key to close)“);
                Console.ReadKey();
            }
        }

        static void CallEvent()
        {
            WaitForEvent = true;
            while (WaitForEvent)
            {
                EDSDK.EdsGetEvent();
                Thread.Sleep(200);
            }
        }

        static uint handler_SDKobjectEvent(uint inEvent IntPtr inRef IntPtr inContext)
        {
            if (inEvent == EDSDK.objectEvent_DirItemRequestTransfer || inEvent == EDSDK.objectEvent_DirItemCreated) WaitForEvent = false;
            return EDSDK.EDS_ERR_OK;
        }

        static void handler_CameraAdded()
        {
            List cameras = CameraHandler.GetCameraList();
            if (cameras.Count > 0) CameraHandler.OpenSession(cameras[0]);
            Console.WriteLine(“Opened session with camera: “ + cameras[0].Info.szDeviceDescription);
            WaitForEvent = false;
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-03-23 18:28  CanonSDKTutorial\
     目录           0  2016-03-23 15:53  CanonSDKTutorial\.vs\
     目录           0  2016-03-23 15:53  CanonSDKTutorial\.vs\CanonSDKTutorial\
     目录           0  2016-03-23 18:23  CanonSDKTutorial\.vs\CanonSDKTutorial\v14\
     文件       40960  2016-03-23 18:29  CanonSDKTutorial\.vs\CanonSDKTutorial\v14\.suo
     文件        2402  2015-04-24 04:11  CanonSDKTutorial\CanonSDKTutorial.sln
     目录           0  2016-03-23 15:53  CanonSDKTutorial\ConsoleExample\
     目录           0  2015-08-06 19:51  CanonSDKTutorial\ConsoleExample\bin\
     目录           0  2016-03-23 18:31  CanonSDKTutorial\ConsoleExample\bin\Debug\
     目录           0  2015-08-06 19:53  CanonSDKTutorial\ConsoleExample\bin\Release\
     文件        6656  2015-08-06 19:44  CanonSDKTutorial\ConsoleExample\bin\Release\ConsoleExample.exe
     文件       64000  2015-08-06 19:44  CanonSDKTutorial\ConsoleExample\bin\Release\EDSDKLib.dll
     文件       24987  2015-08-06 19:44  CanonSDKTutorial\ConsoleExample\bin\Release\EDSDKLib.xml
     文件        2484  2015-04-24 04:11  CanonSDKTutorial\ConsoleExample\ConsoleExample.csproj
     目录           0  2016-03-23 15:53  CanonSDKTutorial\ConsoleExample\obj\
     目录           0  2016-03-23 15:53  CanonSDKTutorial\ConsoleExample\obj\x86\
     目录           0  2016-03-23 18:31  CanonSDKTutorial\ConsoleExample\obj\x86\Debug\
     文件        2724  2014-11-12 22:26  CanonSDKTutorial\ConsoleExample\Program.cs
     目录           0  2015-08-06 19:51  CanonSDKTutorial\ConsoleExample\Properties\
     文件        1440  2014-11-12 20:35  CanonSDKTutorial\ConsoleExample\Properties\AssemblyInfo.cs
     目录           0  2016-03-23 18:23  CanonSDKTutorial\EDSDKLib\
     目录           0  2015-08-06 19:51  CanonSDKTutorial\EDSDKLib\bin\
     目录           0  2016-03-23 18:31  CanonSDKTutorial\EDSDKLib\bin\Debug\
     目录           0  2015-08-06 19:53  CanonSDKTutorial\EDSDKLib\bin\Release\
     文件       64000  2015-08-06 19:44  CanonSDKTutorial\EDSDKLib\bin\Release\EDSDKLib.dll
     文件       24987  2015-08-06 19:44  CanonSDKTutorial\EDSDKLib\bin\Release\EDSDKLib.xml
     文件       85392  2016-03-23 18:23  CanonSDKTutorial\EDSDKLib\CameraClasses.cs
     文件      123379  2016-03-23 18:07  CanonSDKTutorial\EDSDKLib\EDSDK.cs
     文件        2471  2015-04-24 04:11  CanonSDKTutorial\EDSDKLib\EDSDKLib.csproj
     目录           0  2016-03-23 15:53  CanonSDKTutorial\EDSDKLib\obj\
     目录           0  2016-03-23 15:53  CanonSDKTutorial\EDSDKLib\obj\x86\
............此处省略92个文件信息

评论

共有 条评论

相关资源