Esempio n. 1
0
        public void CreateSessionFiles(SessionTemplateCollection sessionPhotos)
        {
            //Get current sessions
            var sessions = Directory.GetDirectories("Images");
            var newDirId = 0;

            if (sessions.Any())//Get last sessionId
            {
                newDirId = sessions.Select(dir => int.Parse(dir.Split('\\').Last().Split('_').Last())).Max();
            }

            var newDir = Directory.CreateDirectory(@"Images\Session_" + (newDirId + 1));

            SaveFrameToFile(Path.Combine(newDir.FullName, "SessionTemplate.jpg"), sessionPhotos.SessionTemplatePhoto);

            var gifStream = GenerateGifStream(sessionPhotos);

            SaveStreamToFile(Path.Combine(newDir.FullName, "session.gif"), gifStream);

            var i = 1;

            foreach (Photo photo in sessionPhotos)
            {
                SaveFrameToFile(Path.Combine(newDir.FullName, "img_" + i + ".jpg"), photo.Image);
                i++;
            }
        }
Esempio n. 2
0
        public MemoryStream GenerateGifStream(SessionTemplateCollection sessionPhotos)
        {
            GifBitmapEncoder gifEncoder = new GifBitmapEncoder();

            foreach (Photo photo in sessionPhotos)
            {
                gifEncoder.Frames.Add(photo.Image);
            }

            MemoryStream memory = new MemoryStream();

            gifEncoder.Save(memory);

            return(memory);
        }
        public TemplatePreview(SessionTemplate template, SessionTemplateCollection sessionPhotos)
        {
            InitializeComponent();
            _template = template;
            template.AttachToControl(frPreview);

            var i = 0;

            foreach (Canvas pose in template.Poses)
            {
                var image = new Image();
                image.Width   = pose.Width;
                image.Height  = pose.Height;
                image.Source  = sessionPhotos[i].Image;
                image.Stretch = Stretch.Uniform;
                pose.Children.Add(image);
                pose.Background = new SolidColorBrush(Colors.Transparent);

                i++;
            }
        }
Esempio n. 4
0
        public SharePhotos(SessionTemplateCollection sessionPhotos)
        {
            InitializeComponent();
            _sessionPhotos = sessionPhotos;

            _template = Settings.CurrentTemplate;

            _templatePreview = new TemplatePreview(_template, sessionPhotos);
            frPreview.Navigate(_templatePreview);

            var brush = new ImageBrush();
            var sMgr  = new SessionManager();

            gifStream         = sMgr.GenerateGifStream(sessionPhotos);
            brush.ImageSource = sMgr.ImageFromStream(gifStream);

            btnPreviewGif.Background = brush;

            var templateBrush = new ImageBrush();

            templateBrush.ImageSource = _template.RenderToBitmap();

            btnPreviewTemplate.Background = templateBrush;
        }
Esempio n. 5
0
        public LivePreview(string deviceMoniker)
        {
            InitializeComponent();
            photoCollection = (SessionTemplateCollection)(Resources["SessionTemplatePhotos"] as ObjectDataProvider).Data;
            //TODO: Update collection count property based on the selected session template
            //photoCollection.PhotoCount = Get Current Session Template placeholders count.
            // enumerate video devices

            photoCollection.PhotoCount = Settings.CurrentTemplate.Poses.Count;

            // create video source from selected device
            videoSource = new VideoCaptureDevice(deviceMoniker);

            // set NewFrame event handler
            videoSource.NewFrame += delegate(object source, NewFrameEventArgs args)
            {
                try
                {
                    args.Frame.RotateFlip(RotateFlipType.RotateNoneFlipX);
                    var img = (Bitmap)args.Frame.Clone();

                    Dispatcher.BeginInvoke(new ThreadStart(delegate
                    {
                        lastFrame          = BitmapFrame.Create(ToBitmapImage(img));;
                        frameHolder.Source = lastFrame;
                    }));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            };

            videoSource.SnapshotFrame += delegate(object source, NewFrameEventArgs args)
            {
                args.Frame.RotateFlip(RotateFlipType.RotateNoneFlipX);
                var img = (Bitmap)args.Frame.Clone();
                lastFrame = BitmapFrame.Create(ToBitmapImage(img));
                UpdateTemplateStackData(lastFrame);
            };

            try
            {
                // start the video source
                videoSource.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            App.Current.Exit += delegate
            {
                videoSource?.SignalToStop();

                dispatcherTimer?.Stop();
            };

            Loaded += delegate
            {
                NavigationService.Navigated += delegate
                {
                    videoSource?.SignalToStop();

                    dispatcherTimer?.Stop();
                };
            };

            if (!string.IsNullOrWhiteSpace(deviceMoniker))
            {
                dispatcherTimer          = new DispatcherTimer();
                dispatcherTimer.Tick    += dispatcherTimer_Tick;
                dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1, 500);
                dispatcherTimer.Start();
            }
        }