Ejemplo n.º 1
0
        // InitializeCamera() opens the camera session via the canon sdk wrapper, sets the right modes and starts the live view image feed
        private bool InitializeCamera(Camera camera)
        {
            try
            {
                CameraWrapper.OpenSession(camera);
                Console.Write("Done.\nAdjusting settings...");
                CameraWrapper.SetSetting(EDSDK.PropID_Av, CameraValues.AV(Settings.Av));
                CameraWrapper.SetSetting(EDSDK.PropID_Tv, CameraValues.TV(Settings.Tv));
                CameraWrapper.SetSetting(EDSDK.PropID_ISOSpeed, CameraValues.ISO(Settings.ISO));
                CameraWrapper.SetSetting(EDSDK.PropID_WhiteBalance, (uint)Settings.WB);

                Console.Write("Done.\nStarting LiveView...");
                LiveViewUpdating = false;
                CameraWrapper.StartLiveView();

                if (CameraWrapper.IsLiveViewOn)
                {
                    Console.WriteLine("Done.");
                    return(true);
                }
                Console.WriteLine("Error!\n-> LiveView dit not start for some reason.");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error!\n-> " + e.Message);
            }
            return(false);
        }
Ejemplo n.º 2
0
 // Disconnect camera
 private void CloseCamera()
 {
     if (!CameraWrapper.CameraSessionOpen)
     {
         return;
     }
     if (!CameraWrapper.IsLiveViewOn)
     {
         return;
     }
     // Unset Depth of Field Preview to avoid errorous states in the camera
     CameraWrapper.SetSetting(EDSDK.PropID_Evf_DepthOfFieldPreview, 0);
     LiveViewUpdating = false;
     // Don't call CloseSession() here! The SetSetting call above will result in a exception in a different thread in the CanonEDSDKWrapper
     // The wrapper will call closesession when it is needed
 }
Ejemplo n.º 3
0
 // LiveViewUpdated() is called from the canon sdk wrapper when a new image is read from the camera and is ready for processing
 // LiveViewUpdated() writes the image to the anonymous memory pipe.
 // An IO error will terminate the application.
 // Depth Of Field Preview mode is also enabled after the first received image (to avoid a black screen)
 private void LiveViewUpdated(Stream img)
 {
     // Check if first image
     if (!LiveViewUpdating)
     {
         Console.WriteLine("Received first image from camera. Enabling Depth of Field Preview.");
         // Enable Depth of Field Preview mode for auto focus
         // Enabling it now seems to work better than right after calling StartLiveView() (for some reason)
         CameraWrapper.SetSetting(EDSDK.PropID_Evf_DepthOfFieldPreview, 1);
         LiveViewUpdating = true;
     }
     if (PipeClient.IsConnected)
     {
         try
         {
             // Protocol: int32 [image length] + length amount of image data in bytes
             int written;
             int length = (int)img.Length;
             if (length <= 0)
             {
                 return;
             }
             byte[] buffer = new byte[length];
             PipeWriter.Write(length);
             while ((written = img.Read(buffer, 0, buffer.Length)) != 0)
             {
                 PipeWriter.Write(buffer, 0, written);
             }
             PipeWriter.Flush();
         }
         catch (IOException e)
         {
             Console.WriteLine("Pipe error: {0}", e.Message);
             CloseCamera();
             Application.Exit();
         }
     }
     else
     {
         Console.WriteLine("Pipe disconnected during image update, exiting...");
         CloseCamera();
         Application.Exit();
     }
 }