0

在 Visual Studio 中,我有一个程序,当前每次单击按钮时都会拍摄 5 张照片。我希望程序拍摄这 5 张照片,然后更改光圈设置并拍摄最后一张照片。没有真正相关的代码,所以这是为已经了解 SDK 的人准备的。

我已经四处寻找如何处理这个问题,但我对一般的编码相当缺乏经验。

谢谢!

也许有用的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using EDSDKLib;

using CanonCameraAppLib;
using CanonCameraAppLib.Remote;

namespace CanonCameraApp

{ 
public partial class CanonCameraApp : Form
{
    public delegate void TakePhotoDelegate(int delay);

    private CameraAPI api;
    private RemoteServer server;
    private TakePhotoDelegate takePhotoDelegate;        

    public CanonCameraApp()
    {
        InitializeComponent();
        api = CameraAPI.Instance;
        takePhotoDelegate = new TakePhotoDelegate(takePhotograph);

        init();            
    }

    private void server_OnTakePhotoCommandEvent(RemoteCommandEventArgs e)
    {
        this.Invoke(takePhotoDelegate, e.Delay);
    }

    private void init()
    {
        loadCameras();
        registerEvents();
        if (Convert.ToBoolean(ConfigurationManager.AppSettings["StartServerOnStartup"]))
        {
            startServerListener();
        }
    }

    private void registerEvents()
    {
        CameraAPI.OnCameraAdded += new CameraAddedEventHandler(api_OnCameraAdded);
    }

    private void api_OnCameraAdded(CameraAddedEventArgs e)
    {
        scanForCamerasToolStripMenuItem_Click(null, new EventArgs());
    }

    private void startServerListener()
    {
        server = new RemoteServer(Convert.ToInt32(ConfigurationManager.AppSettings["ListenPort"]));
        server.OnTakePhotoCommandEvent += new TakePhoto(server_OnTakePhotoCommandEvent);
        new Thread(server.Start).Start();
    }

    private void loadCameras()
    {
        try
        {
            cbCameras.DataSource = api.Cameras;
            cbCameras.DisplayMember = "Name";
            cbCameras.Enabled = true;
            btnTakePhoto.Enabled = true;
            btnProperties.Enabled = true;
            scanForCamerasToolStripMenuItem.Enabled = false;
            subscribeToEvents();
        }
        catch (CameraNotFoundException)
        {
            MessageBox.Show("No cameras were detected.  Please make sure that they are plugged in and are turned on.");
            cbCameras.Enabled = false;
            btnTakePhoto.Enabled = false;
            btnProperties.Enabled = false;
            scanForCamerasToolStripMenuItem.Enabled = true;
        }
    }

    private void subscribeToEvents()
    {
        List<Camera> cameras = getCameraList();

        foreach (Camera camera in cameras)
        {
            camera.OnNewItemCreated += new CanonCameraAppLib.Events.NewItemCreatedEventHandler(camera_OnNewItemCreated);
        }
    }

    void camera_OnNewItemCreated(Camera sender, CanonCameraAppLib.Events.NewItemCreatedEventArgs e)
    {
        if (chbPreview.Checked)
        {
            PhotoPreview preview = new PhotoPreview(e.Item, true);
            preview.Show();
        }
    }
  //  private void changeAperature(int value)
    //{
      //  Camera camera = getSelectedCamera();

    //    camera.changeAperture(value);
    //}
    private void takePhotograph(int delay)
    {
        Camera camera = getSelectedCamera();

        camera.takePhotograph(delay);
    }


    private Camera getSelectedCamera()
    {
        return (Camera)cbCameras.SelectedItem;
    }

    private List<Camera> getCameraList()
    {
        List<Camera> cameras = new List<Camera>(cbCameras.Items.Count);

        foreach (object camera in cbCameras.Items)
        {
            cameras.Add((Camera)camera);
        }

        return cameras;
    }

    #region Handled Form Events

        private void button1_Click(object sender, EventArgs e)
        {

            for (int i = 0; i <=4; i++)
                takePhotograph(Convert.ToInt16(textBox1.Text));
            for (int i = 0; i <= 1; i++) 

                ;
        }

        private void scanForCamerasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            loadCameras();
        }

        private void quitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            quit();
        }

        private void CanonCameraApp_FormClosing(object sender, FormClosingEventArgs e)
        {
            quit();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new About().ShowDialog(this);
        }

        /// <summary>
        /// Opens the Camera Properties window
        /// </summary>
        private void btnProperties_Click(object sender, EventArgs e)
        {
            new CameraProperties(getSelectedCamera()).Show();
        }

    #endregion

    private void quit()
    {
        if (server != null)
        {
            server.Stop();
        }
        Application.ExitThread();
        Application.Exit();
    }
}
}

这就是它自己的应用程序的样子。有几个dll和其他涉及的东西。

4

0 回答 0