示例#1
0
        public override Task StartConvertingAsyncTask()
        {
            return Task.Run(() =>
            {
                Encoder = new AnimatedGifEncoder();
                _mediaDetector = new MediaDetector();
                _mediaDetector.LoadMedia(Path);

                ConvertingProgressBar.Dispatcher.Invoke(
                    DispatcherPriority.Normal,
                    new Action(() =>
                    {
                        ConvertingProgressBar.Value = 0;
                        ConvertingProgressBar.Maximum = (To - From) * Fps / 1000;
                    }));
                Encoder.Start(GifPath);
                Encoder.SetDelay(Ival);
                Encoder.SetRepeat(0);
                for (var i = From; i < To; i += Ival)
                {
                    var frame = GetFrame(TimeSpan.FromMilliseconds(i));
                    if (GifSize.Height != -1 && GifSize.Width != -1)
                        frame = ResizeImage(frame);
                    AddFrame(frame);
                    ConvertingProgressBar.Dispatcher.Invoke(
                        DispatcherPriority.Normal,
                        new Action(() =>
                        {
                            ConvertingProgressBar.Value++;
                        }));
                }
                Encoder.Finish();
            });
        }
        public MediaDetectorElement()
        {
            m_frames = new ObservableCollection<VideoFrame>();
            Frames = new ReadOnlyObservableCollection<VideoFrame>(m_frames);

            m_mediaDetector = CreateMediaDetector();
            Loaded += MediaDetectorElement_Loaded;
        }
        private static MediaDetector CreateMediaDetector()
        {
            MediaDetector detector = null;

            /* The reset event will block our thread while
             * we create an intialize the player */
            var reset = new ManualResetEvent(false);

            /* We need to create a new thread for our Dispatcher */
            var t = new Thread((ThreadStart) delegate
            {
                detector = new MediaDetector();

                /* We queue up a method to execute
                 * when the Dispatcher is ran.
                 * This will wake up the calling thread
                 * that has been blocked by the reset event */
                detector.Dispatcher.Invoke((Action) (() => reset.Set()));

                Dispatcher.Run();
            })
            {
                Name = "MediaDetector",
                IsBackground = true
            };

            t.SetApartmentState(ApartmentState.STA);

            /* Starts the thread and creates the object */
            t.Start();

            /* We wait until our object is created and
             * the new Dispatcher is running */
            reset.WaitOne();

            return detector;
        }