Пример #1
0
        public void Run()
        {
            try
            {
                PrintManager.PrintBatchHandler batch1 = _printManager.startNewBatch(PrintTemplateType.Wide);
                batch1.AddImage(GetImageSourceFromPath("pack://application:,,,/Kinect_Standing.bmp"));
                batch1.AddImage(GetImageSourceFromPath("pack://application:,,,/Kinect_Standing.bmp"));
                batch1.CompleteBatch(1);

                PrintManager.PrintBatchHandler batch2 = _printManager.startNewBatch(PrintTemplateType.Wide);
                batch2.AddImage(GetImageSourceFromPath("pack://application:,,,/Kinect_Standing.bmp"));
                batch2.AddImage(GetImageSourceFromPath("pack://application:,,,/Kinect_Leaning.bmp"));
                batch2.CompleteBatch(1);

                PrintManager.PrintBatchHandler batch3 = _printManager.startNewBatch(PrintTemplateType.Wide);
                batch3.AddImage(GetImageSourceFromPath("pack://application:,,,/Kinect_Leaning.bmp"));
                batch3.AddImage(GetImageSourceFromPath("pack://application:,,,/Kinect_Standing.bmp"));
                batch3.CompleteBatch(1);

                PrintManager.PrintBatchHandler batch4 = _printManager.startNewBatch(PrintTemplateType.Wide);
                batch4.AddImage(GetImageSourceFromPath("pack://application:,,,/Kinect_Leaning.bmp"));
                batch4.AddImage(GetImageSourceFromPath("pack://application:,,,/Kinect_Leaning.bmp"));
                batch4.CompleteBatch(2);

                //System.Diagnostics.Debug.WriteLine("Print result: " + (result ? "success" : "failure"));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("=========== Exception In Main ===========");
                System.Diagnostics.Debug.WriteLine("{0}", ex.Message);
                System.Diagnostics.Debug.WriteLine("=========================================");
            }
        }
Пример #2
0
        public MainWindow()
        {
            InitializeComponent();
            _buttonListener = new ButtonListener(ButtonPressHandler);

            // Setup key actions
            _keyActions.Add(Key.Left, NextBackgroundImage);
            _keyActions.Add(Key.Right, PrevBackgroundImage);
            _keyActions.Add(Key.Up, IncreaseDepthThreshold);
            _keyActions.Add(Key.Down, DecreaseDepthThreshold);
            _keyActions.Add(Key.Space, TakePicture);
            _keyActions.Add(Key.B, TakeBackgroundPicture);

            // Setup button actions
            _buttonActions.Add(0, TakePicture);            // pin 2
            _buttonActions.Add(1, NextBackgroundImage);    // pin 3
            _buttonActions.Add(2, PrevBackgroundImage);    // pin 4
            _buttonActions.Add(3, IncreaseDepthThreshold); // pin 5
            _buttonActions.Add(4, DecreaseDepthThreshold); // pin 6


            StartDialog startDialog = new StartDialog();

            startDialog.ShowDialog();
            _imageSavePath = startDialog.ImageSavePath;
            _printManager  = PrintManager.GetInstance(startDialog.Name, startDialog.PrintCount);
            _printManager.SetPrintErrorInformer(HandlePrintError);
            _currentBatch = _printManager.startNewBatch(PrintTemplateType.Wide);

            _imageProducer = ImageProducerFactory.GetImageProducer();
            _imageProducer.Start();

            // Setup the background images
            _centerCarouselImageIndex = _carouselSize / 2;
            _carouselItemHeight       = (double)_carouselWidth * (108.0f / 192.0f);

            LoadBackgroundImages();
            SetBackgroundImage();
            BuildCarousel();

            _queue = _imageProducer.GetImageQueue();

            _consumer = new Thread(new ThreadStart(Consume));
            _consumer.Start();
            UpdateStatus();

            SetupStates();
        }
Пример #3
0
        public void Run()
        {
            try
            {
                ImageSource[] images = new ImageSource[]
                {
                    GetImageSourceFromPath("backgroundImages/beach.bmp"),
                    GetImageSourceFromPath("backgroundImages/LukeVaderDual.bmp")
                };


                PrintManager.PrintBatchHandler batch1 = _printManager.startNewBatch(PrintTemplateType.Wide);
                batch1.AddImage(images[0]);
                batch1.AddImage(images[1]);
                batch1.CompleteBatch(1);
                //System.Diagnostics.Debug.WriteLine("Print result: " + (result ? "success" : "failure"));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("=========== Exception In Main ===========");
                System.Diagnostics.Debug.WriteLine("{0}", ex.Message);
                System.Diagnostics.Debug.WriteLine("=========================================");
            }
        }
Пример #4
0
        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);
        }