public void StartCamera(string cameraID) { try { BoothState = BoothStates.WaitingForCamera; _latestFrame = null; pictureBoxDisplay.Invalidate(); StopCamera(); CameraDeviceID = cameraID; // create video source CaptureDevice localSource = new CaptureDevice(); localSource.VideoSource = CameraDeviceID; // open it OpenVideoSource(localSource); } catch (Exception ex) { Setup.Log("StartCamera Exception", ex); Setup.LogStat(StatTypes.Error, "StartCamera Exception"); MessageBox.Show(this, "Could not start camera! Please send us your Log.txt file for troubleshooting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void SimpleSetup_Load(object sender, EventArgs e) { try { try { cameraFilters = new FilterCollection(FilterCategory.VideoInputDevice); } catch (Exception exc) { Setup.Log("Could not retrieve camera devices", exc); } if (cameraFilters == null || cameraFilters.Count == 0) { Setup.LogStat(StatTypes.Error, "No cameras found (SimpleMode)"); MessageBox.Show(this, "Sorry! We could not detect a web camera. Are you sure it's plugged in?\n\nDouble check your web camera settings and try \"Easy Photo Booth\" again.", "No web camera detected", MessageBoxButtons.OK, MessageBoxIcon.Stop); Application.Exit(); } } catch (Exception ex) { Setup.Log("Cannot load simple setup form", ex); MessageBox.Show(this, "Could not start application! Please send us your Log.txt file for troubleshooting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
static void Main() { Setup.Log("Starting application"); Setup.LogStat(StatTypes.Launch); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new CameraForm()); }
private void BTN_ViewImages_Click(object sender, EventArgs e) { try { Setup.LogStat(StatTypes.ViewImagesSimple); Process.Start(Settings.ImagePath); } catch (Exception ex) { Setup.Log("Could not open imagesPath", ex); Setup.LogStat(StatTypes.Error, "ViewImages (SimpleMode) Exception"); } }
private void BTN_Advanced_Click(object sender, EventArgs e) { try { Setup.LogStat(StatTypes.AdvancedMode); this.Hide(); CameraForm.Instance.LastSetupForm = CameraForm.Instance.SetupForm; CameraForm.Instance.SetupForm.Show(); } catch (Exception ex) { Setup.Log("Could not goto advanced mode", ex); Setup.LogStat(StatTypes.Error, "GotoAdvancedMode Exception"); } }
public void ReloadSettings() { try { ImagePath = Settings.ImagePath; if (!Directory.Exists(ImagePath)) { Directory.CreateDirectory(ImagePath); } SinglesImagePath = Path.Combine(ImagePath, "Individual"); if (!Directory.Exists(SinglesImagePath)) { Directory.CreateDirectory(SinglesImagePath); } GroupImagePath = Path.Combine(ImagePath, "FilmStrip"); if (!Directory.Exists(GroupImagePath)) { Directory.CreateDirectory(GroupImagePath); } Frames = new List <Image>(); string framesPath = Settings.OverlaysPath; if (!Directory.Exists(framesPath)) { Directory.CreateDirectory(framesPath); } foreach (string framePath in Directory.GetFiles(framesPath, "*.png")) { Frames.Add(Image.FromFile(framePath)); } CycleFrames = Settings.CycleOverlays; SecondsToWait = Settings.SecondsToWait; Rounds = Settings.Rounds; BoothState = BoothStates.Idle; roundsRemaining = Rounds; secondsRemaining = SecondsToWait; } catch (Exception ex) { Setup.Log("ReloadSettings Exception", ex); } }
private void BTN_Start_Click(object sender, EventArgs e) { try { Setup.LogStat(StatTypes.StartPhotoBoothSimple); MessageBox.Show(this, "Photo Booth will now start. Press the 'Q' key to leave at any time.", "About to start...", MessageBoxButtons.OK, MessageBoxIcon.Information); Setup.Log("Starting photo booth from simple mode:\r\n\tImagePath: " + Settings.ImagePath + "\r\n\tOverlaysPath: " + Settings.OverlaysPath + "\r\n\tRounds: " + Settings.Rounds + "\r\n\tSecondsToWait: " + Settings.SecondsToWait + "\r\n\tSecondsToPreview: " + Settings.SecondsToPreview); this.Hide(); CameraForm.Instance.ReloadSettings(); CameraForm.Instance.StartCamera(cameraFilters[0].MonikerString); CameraForm.Instance.Show(); } catch (Exception ex) { Setup.Log("Could not start photobooth", ex); Setup.LogStat(StatTypes.Error, "StartPhotoBooth (SimpleMode) Exception"); } }
//private Timer PictureTimer = null; void onTick() { try { if (BoothState == BoothStates.GetReady) { secondsRemaining--; if (secondsRemaining == 0) { secondsRemaining = Settings.SecondsToWait; BoothState = BoothStates.Countdown; SND_Tick.Play(); } } else if (BoothState == BoothStates.Countdown) { secondsRemaining--; if (secondsRemaining == 0) { secondsRemaining = 2; BoothState = BoothStates.TakePicture; SND_Smile.Play(); } else { SND_Tick.Play(); } } else if (BoothState == BoothStates.TakePicture) { secondsRemaining--; if (secondsRemaining == 0) { secondsRemaining = Settings.SecondsToWait; SND_CameraClick.Play(); // Take picture and save Flash(); SavePicture(); roundsRemaining--; if (roundsRemaining == 0) { NextTickDate = null; //PictureTimer.Stop(); SavePictures(); ShowPreview(); } else { BoothState = BoothStates.GetReady; secondsRemaining = 2; if (CycleFrames) { NextFrame(false); } } } } } catch (Exception ex) { Setup.Log("onTick Exception", ex); } if (NextTickDate != null) { NextTickDate = DateTime.Now.AddSeconds(1); } }
private void Log(string msg) { LogMsg = msg; LogMsgEndDate = DateTime.Now.AddSeconds(2); Setup.Log(msg); }
private void CameraForm_Load(object sender, EventArgs e) { try { Instance = this; pictureBoxDisplay.Paint += new PaintEventHandler(drawLatestImage); this.Hide(); SplashForm = new Splash(); SplashForm.Show(); /* * if (CameraService.AvailableCameras.Count == 0) * { * Setup.Log("CameraForm_Load NO WEB CAMS FOUND"); * MessageBox.Show(this, "Sorry! We could not detect a web camera. Are you sure it's plugged in?\n\nDouble check your web camera settings and try \"easy Photo Booth\" again.", "No web camera detected", MessageBoxButtons.OK, MessageBoxIcon.Stop); * Application.Exit(); * } */ SplashTimer = new Timer(); SplashTimer.Interval = 5000; SplashTimer.Tick += timer_Tick; SplashTimer.Start(); //SetupForm = new Setup(); //SetupForm.Show(); SND_CameraClick = new SoundPlayer(Properties.Resources.CameraClick); SND_CameraClick.Load(); SND_Tick = new SoundPlayer(Properties.Resources.Tick); SND_Tick.Load(); SND_Smile = new SoundPlayer(Properties.Resources.FastTick); SND_Smile.Load(); Setup.Log("Current directory: " + Directory.GetCurrentDirectory()); /* * if (!DesignMode) * { * // Refresh the list of available cameras * comboBoxCameras.Items.Clear(); * foreach (Camera cam in CameraService.AvailableCameras) * comboBoxCameras.Items.Add(cam); * * if (comboBoxCameras.Items.Count > 0) * comboBoxCameras.SelectedIndex = 0; * * ReloadSettings(); * * if (comboBoxCameras.Items.Count > 0) * { * CameraFound = true; * * // start camera * if (_frameSource != null && _frameSource.Camera == comboBoxCameras.SelectedItem) * return; * * thrashOldCamera(); * startCapturing(); * } * else * { * pictureBoxDisplay.Visible = false; * _latestFrame = new Bitmap(pictureBoxDisplay.Width, pictureBoxDisplay.Height); * } * } * */ } catch (Exception ex) { Setup.Log("CameraForm_Load Exception", ex); Setup.LogStat(StatTypes.Error, "CameraForm_Load Exception"); MessageBox.Show(this, "Could not start application! Please send us your Log.txt file for troubleshooting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Application.Exit(); } }
/* * private Camera CurrentCamera * { * get * { * return comboBoxCameras.SelectedItem as Camera; * } * } */ /* * private void btnStart_Click(object sender, EventArgs e) * { * // Early return if we've selected the current camera * if (_frameSource != null && _frameSource.Camera == comboBoxCameras.SelectedItem) * return; * * thrashOldCamera(); * startCapturing(); * } * * private void startCapturing() * { * try * { * Camera c = (Camera)comboBoxCameras.SelectedItem; * setFrameSource(new CameraFrameSource(c)); * _frameSource.Camera.CaptureWidth = 640; * _frameSource.Camera.CaptureHeight = 480; * _frameSource.Camera.Fps = 50; * _frameSource.NewFrame += OnImageCaptured; * * pictureBoxDisplay.Paint += new PaintEventHandler(drawLatestImage); * cameraPropertyValue.Enabled = _frameSource.StartFrameCapture(); * } * catch (Exception ex) * { * comboBoxCameras.Text = "Select A Camera"; * MessageBox.Show(ex.Message); * } * } */ private void Draw(Graphics g) { try { if (BoothState == BoothStates.WaitingForCamera) { DrawText("Waiting for camera to start...", g, 32, Color.Green, FontPosition.Middle); return; } if (_latestFrame == null) { return; } if (NextTickDate != null && NextTickDate.Value <= DateTime.Now) { onTick(); } // Draw the latest image from the active camera float width = _latestFrame.Width; float height = _latestFrame.Height; float ratio = height / width; float newWidth = pictureBoxDisplay.Width; float newHeight = newWidth * ratio; if (newHeight > pictureBoxDisplay.Height) { float scale = (float)pictureBoxDisplay.Height / newHeight; newHeight *= scale; newWidth *= scale; } float xPos = (pictureBoxDisplay.Width - newWidth) / 2; float yPos = (pictureBoxDisplay.Height - newHeight) / 2; //e.Graphics.DrawImage(_latestFrame, 0, 0, _latestFrame.Width, _latestFrame.Height); //float ratio = (float)_latestFrame.Height / (float)_latestFrame.Width; g.DrawImage(_latestFrame, xPos, yPos, newWidth, newHeight); if (CurrentFrameImage != null) { g.DrawImage(CurrentFrameImage, xPos, yPos, newWidth, newHeight); } //e.Graphics.DrawString("CLICK TO TAKE PICTURES", FontStyl if (BoothState == BoothStates.Idle) { DrawText("LEFT CLICK TO TAKE PICTURES", g, 32, Color.Red, FontPosition.Middle); if (Frames.Count > 0) { DrawText("Right click for different overlays", g, 25, Color.Blue, FontPosition.Bottom); } } else if (BoothState == BoothStates.GetReady) { DrawText("GET READY...", g, 32, Color.Green, FontPosition.Middle); } else if (BoothState == BoothStates.Countdown) { DrawText(secondsRemaining.ToString(), g, 64, Color.Green, FontPosition.Top); DrawText("Taking photo " + (Rounds - roundsRemaining + 1) + " of " + Rounds + "...", g, 25, Color.Blue, FontPosition.Middle); } else if (BoothState == BoothStates.TakePicture) { DrawText("SMILE!", g, 64, Color.Yellow, FontPosition.Top); } if (FlashEndDate != null) { if (FlashEndDate.Value >= DateTime.Now) { g.FillRectangle(new SolidBrush(Color.White), 0, 0, pictureBoxDisplay.Width, pictureBoxDisplay.Height); } else { FlashEndDate = null; } } else if (PreviewEndDate != null) { if (PreviewEndDate.Value >= DateTime.Now && ImagesSaved != null && ImagesSaved.Count > 0) { g.FillRectangle(new SolidBrush(Color.FromArgb(230, 200, 200, 200)), 0, 0, pictureBoxDisplay.Width, pictureBoxDisplay.Height); Image img = Image.FromFile(PreviewImage); width = img.Width; height = img.Height; ratio = height / width; newWidth = pictureBoxDisplay.Width; newHeight = newWidth * ratio; xPos = 0; yPos = (pictureBoxDisplay.Height - newHeight) / 2; g.DrawImage(img, xPos, yPos, newWidth, newHeight); } else { PreviewEndDate = null; BoothState = BoothStates.Idle; } } if (!String.IsNullOrEmpty(LogMsg)) { if (LogMsgEndDate != null && LogMsgEndDate.Value >= DateTime.Now) { DrawText(LogMsg, g, 20, Color.Blue, FontPosition.Bottom); } else { LogMsg = null; LogMsgEndDate = null; } } } catch (Exception ex) { Setup.Log("Draw Exception", ex); } }