private void LoadBackgroundImages() { _loadingBackgrounds = true; UpdateStatus(); String bmpDir = AppDomain.CurrentDomain.BaseDirectory + "backgroundImages"; if (Directory.Exists(bmpDir)) { String[] filePaths = Directory.GetFiles(bmpDir, "*.bmp"); int index = 0; BackgroundImage[] backgroundImages = new BackgroundImage[filePaths.Count()]; Dictionary <string, BitmapSource> backgroundImageMap = new Dictionary <string, BitmapSource>(); foreach (String path in filePaths) { try { String name = System.IO.Path.GetFileNameWithoutExtension(path); BitmapImage thisImage = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute)); thisImage.Freeze(); // Only accept images of the correct size if (thisImage.PixelHeight == 1080 && thisImage.PixelWidth == 1920) { BackgroundImage thisBackgroundImage = backgroundImages[index++] = new BackgroundImage(name, thisImage); backgroundImageMap.Add(name, thisBackgroundImage.FlippedImage); } } catch (Exception ex) { } } // Trim the array in case we didn't use all of the images Array.Resize <BackgroundImage>(ref backgroundImages, index); _backgroundIterator = new ContinousIterator <BackgroundImage>(backgroundImages); _imageProducer.SetConfiguration(ImageProducerConfiguration.Simple("setBackgroundImages", backgroundImageMap)); } _loadingBackgrounds = false; UpdateStatus(); }
private void UpdateDepthThreshold() { _imageProducer.SetConfiguration(ImageProducerConfiguration.Simple("depthThreshold", _depthThresholdInMeters)); }
private void SetBackgroundImage() { _imageProducer.SetConfiguration(ImageProducerConfiguration.Simple("selectBackgroundImage", _backgroundIterator.Current.Name)); }
private void SetupStates() { SELECT_BACKGROUND = new State("SELECT_BACKGROUND", (eventType, eventArgs, stateData) => { switch (eventType) { case EventType.TRANSITION_TO_STATE: ChangeState(SELECT_BACKGROUND); Dispatcher.Invoke(() => tabControl.SelectedIndex = 0); if (_currentBatch.TemplateFull) { _currentBatch = _printManager.startNewBatch(PrintTemplateType.Wide); } UpdateStatus(); break; case EventType.PREVIEW_IMAGE_ARRIVED: if (!_havePrintError) { Dispatcher.Invoke(() => backgroundPreview.Source = eventArgs as ImageSource); } break; case EventType.TAKE_PICTURE_REQUEST: if (!_havePrintError) { COUNTDOWN.HandleEvent(EventType.TRANSITION_TO_STATE, null); } break; case EventType.PRINT_ERROR: DefaultPrintErrorHandler(eventArgs as String); break; } }); COUNTDOWN = new State("COUNTDOWN", (eventType, eventArgs, stateData) => { Thread countdownThread; switch (eventType) { case EventType.TRANSITION_TO_STATE: ChangeState(COUNTDOWN); Dispatcher.Invoke(() => { tabControl.SelectedIndex = 1; countdownPreview.Source = backgroundPreview.Source; }); countdownThread = new Thread(() => { while (_havePrintError) { } int countDown = _countdownLength; while (countDown > 0) { Dispatcher.Invoke(() => countdownLabel.Content = countDown.ToString()); Thread.Sleep(500); Dispatcher.Invoke(() => countdownLabel.Content = ""); Thread.Sleep(500); countDown--; } Dispatcher.Invoke(() => countdownLabel.Content = "SMILE !"); Thread.Sleep(2000); Dispatcher.Invoke(() => countdownLabel.Content = ""); //_readyForCapture = true; _imageProducer.SetConfiguration(ImageProducerConfiguration.Simple("captureHighQuality")); }); countdownThread.Start(); break; case EventType.PREVIEW_IMAGE_ARRIVED: if (!_havePrintError) { Dispatcher.Invoke(() => countdownPreview.Source = eventArgs as ImageSource); } break; case EventType.IMAGE_CAPTURED: BitmapSource image = eventArgs as BitmapSource; if (_createNewBackground) { _createNewBackground = false; String timeStamp = BuildTimestampString(); WriteImageFile(image, BuildAbsoluteFilePath(_backgroundImagePath, timeStamp, "bmp")); _backgroundIterator.Add(new BackgroundImage(timeStamp, image)); _backgroundIterator.MoveLast(); UpdateCarousel(); Dictionary <String, BitmapSource> outMap = new Dictionary <string, BitmapSource>(); outMap.Add(timeStamp, image); _imageProducer.SetConfiguration(ImageProducerConfiguration.Simple("addBackgroundImages", outMap)); } else { _currentBatch.AddImage(image); WriteImageFile(image, BuildAbsoluteFilePath(_imageSavePath, BuildTimestampString(), "bmp")); } if (_currentBatch.TemplateFull) { Dispatcher.InvokeAsync(() => PRINTING.HandleEvent(EventType.TRANSITION_TO_STATE, null)); } else { Dispatcher.InvokeAsync(() => SELECT_BACKGROUND.HandleEvent(EventType.TRANSITION_TO_STATE, null)); } break; case EventType.PRINT_ERROR: DefaultPrintErrorHandler(eventArgs as String); break; } }); PRINTING = new State("PRINTING", (eventType, eventArgs, stateData) => { switch (eventType) { case EventType.TRANSITION_TO_STATE: ChangeState(PRINTING); Dispatcher.Invoke(() => tabControl.SelectedIndex = 2); _currentBatch.CompleteBatch(_copyCount); Thread waitThread = new Thread(() => { Thread.Sleep(3000); while (_havePrintError) { } Dispatcher.Invoke(() => SELECT_BACKGROUND.HandleEvent(EventType.TRANSITION_TO_STATE, null)); }); waitThread.Start(); break; case EventType.PRINT_ERROR: DefaultPrintErrorHandler(eventArgs as String); break; } }); SELECT_BACKGROUND.HandleEvent(EventType.TRANSITION_TO_STATE, null); }