コード例 #1
0
        public static BitmapImage Capture(
            MediaPlayer player,
            double seconds,
            double maxWidth = 640,
            CRGBA3x3FilteringProc filtering = null,
            int dpi = Image.DEFAULT_dpi
            )
        {
            if (player is null)
            {
                return(null);
            }

            // 指定位置へシーク
            player = (MediaPlayer)player.CloneCurrentValue();

            double volume = player.Volume;

            player.Volume = 0;

            player.Position = TimeSpan.FromSeconds(seconds);
            player.Pause();

            // 読み込みが完了するまで待機
            waitMediaSetup(player, seconds);

            player.Volume = volume;

            return(capture(player, maxWidth, filtering, dpi));
        }
コード例 #2
0
        public static void CaptureOutGifAnimation(
            string path,
            MediaPlayer player,
            double startSeconds             = 0,
            double waitSeconds              = 0.1,
            int count                       = 10,
            double maxWidth                 = 640,
            CRGBA3x3FilteringProc filtering = null,
            int dpi = Image.DEFAULT_dpi)
        {
            if (player is null)
            {
                return;
            }

            // 読み込みが完了するまで待機
            waitMediaSetup(player);

            int width, height;

            // リサイズ後のサイズを計算
            calcRectSize(player, maxWidth, out width, out height);

            double volume = player.Volume;

            player.Volume = 0;

            var gEnc = new GifBitmapEncoder();

            for (int i = 0; i < count; ++i)
            {
                // 指定位置へシーク
                double pos = startSeconds + (double)i * waitSeconds;
                player.Position = TimeSpan.FromSeconds(pos);
                player.Pause();

                // 読み込みが完了するまで待機
                waitMediaSetup(player, pos);

                var renderTarget = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Pbgra32);

                capture(
                    renderTarget,
                    player,
                    width,
                    height,
                    filtering,
                    dpi
                    );

                gEnc.Frames.Add(BitmapFrame.Create(renderTarget));
            }

            player.Volume = volume;

            using (FileStream fs = new FileStream(path, FileMode.Create))
            {
                gEnc.Save(fs);
            }
        }
コード例 #3
0
        public static void CaptureOutGifAnimation(
            string path,
            MediaPlayer player,
            double waitSeconds = 0.1,
            double maxWidth    = 640,
            CRGBA3x3FilteringProc filtering = null,
            int dpi = Image.DEFAULT_dpi
            )
        {
            if (player is null)
            {
                return;
            }

            // 読み込みが完了するまで待機
            waitMediaSetup(player);

            if (!player.NaturalDuration.HasTimeSpan)
            {
                return;
            }

            CaptureOutGifAnimation(
                path,
                player,
                30,
                waitSeconds,
                (int)(player.NaturalDuration.TimeSpan.TotalSeconds / waitSeconds),
                maxWidth,
                filtering,
                dpi
                );
        }
コード例 #4
0
        public static BitmapImage Captures(
            MediaPlayer player,
            double waitSeconds = 10,
            int maxColumns     = 6,
            double maxWidth    = 320,
            CRGBA3x3FilteringProc filtering = null,
            int dpi = Image.DEFAULT_dpi
            )
        {
            if (player is null)
            {
                return(null);
            }

            // 読み込みが完了するまで待機
            waitMediaSetup(player);

            if (!player.NaturalDuration.HasTimeSpan)
            {
                return(null);
            }

            return(Captures(
                       player,
                       30,
                       waitSeconds,
                       (int)(player.NaturalDuration.TimeSpan.TotalSeconds / waitSeconds),
                       maxColumns,
                       maxWidth,
                       filtering,
                       dpi
                       ));
        }
コード例 #5
0
 private static void capture(
     RenderTargetBitmap renderTarget,
     MediaPlayer player,
     double width,
     double height,
     CRGBA3x3FilteringProc filtering = null,
     int dpi = DEFAULT_dpi
     )
 {
     capture(renderTarget, player, 0, 0, width, height, filtering, dpi);
 }
コード例 #6
0
        private static void capture(
            RenderTargetBitmap renderTarget,
            MediaPlayer player,
            double x,
            double y,
            double width,
            double height,
            CRGBA3x3FilteringProc filtering = null,
            int dpi = DEFAULT_dpi
            )
        {
            if (filtering != null)
            {
                var tempRenderTarget = new RenderTargetBitmap((int)width, (int)height, dpi, dpi, PixelFormats.Pbgra32);

                // 動画の映像をレンダリングする
                var visualForVideo = new DrawingVisual();
                using (var context = visualForVideo.RenderOpen())
                {
                    context.DrawVideo(player, new System.Windows.Rect(0, 0, width, height));
                }
                // ビットマップに visualForVideo をレンダリング
                tempRenderTarget.Render(visualForVideo);

                // フィルタリングを通す
                BitmapImage bitmap = RGBA3x3FilteringProc(
                    tempRenderTarget,
                    filtering,
                    (filtering is null) ? true : filtering.useThread,
                    dpi);

                // レンダリングされた動画のイメージを再配置する
                var visualForImage = new DrawingVisual();
                using (var context = visualForImage.RenderOpen())
                {
                    context.DrawImage(bitmap, new System.Windows.Rect(x, y, width, height));
                }
                // ビットマップに visualForImage をレンダリング
                renderTarget.Render(visualForImage);
            }
            else
            {
                // 動画の映像をレンダリングする
                var visualForImage = new DrawingVisual();
                using (var context = visualForImage.RenderOpen())
                {
                    context.DrawVideo(player, new System.Windows.Rect(x, y, width, height));
                }
                // ビットマップに visualForImage をレンダリング
                renderTarget.Render(visualForImage);
            }
        }
コード例 #7
0
        //------------------------------------------------------------------
        private static BitmapImage capture(
            MediaPlayer player,
            double maxWidth,
            CRGBA3x3FilteringProc filtering = null,
            int dpi = DEFAULT_dpi
            )
        {
            int width, height;

            // リサイズ後のサイズを計算
            calcRectSize(player, maxWidth, out width, out height);

            var renderTarget = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Pbgra32);

            capture(renderTarget, player, width, height, filtering, dpi);

            return(Image.ConvertToBitmapImage(renderTarget, Image.ImageType.PNG));
        }
コード例 #8
0
        public static BitmapImage Capture(
            MediaPlayer player,
            double maxWidth = 640,
            CRGBA3x3FilteringProc filtering = null,
            int dpi = Image.DEFAULT_dpi)
        {
            double volume = player.Volume;

            player.Volume = 0;

            player.Pause();

            player.Volume = volume;

            // 読み込みが完了するまで待機
            waitMediaSetup(player);

            return(capture(player, maxWidth, filtering, dpi));
        }
コード例 #9
0
        public static BitmapImage Captures(
            MediaPlayer player,
            double startSeconds             = 0,
            double waitSeconds              = 10,
            int count                       = 10,
            int maxColumns                  = 6,
            double maxWidth                 = 320,
            CRGBA3x3FilteringProc filtering = null,
            int dpi = Image.DEFAULT_dpi)
        {
            if (player is null)
            {
                return(null);
            }

            // 読み込みが完了するまで待機
            waitMediaSetup(player);

            int width, height;

            // リサイズ後のサイズを計算
            calcRectSize(player, maxWidth, out width, out height);

            int widthSize   = width * maxColumns;
            int heightCount = count / maxColumns;

            heightCount = (heightCount == 0) ? 1 : heightCount;
            int heightSize = height * heightCount;

            var renderTarget = new RenderTargetBitmap(widthSize, heightSize, dpi, dpi, PixelFormats.Pbgra32);

            double volume = player.Volume;

            player.Volume = 0;

            for (int i = 0; i < count; ++i)
            {
                // 指定位置へシーク
                double pos = startSeconds + (double)i * waitSeconds;
                player.Position = TimeSpan.FromSeconds(pos);
                player.Pause();

                // 読み込みが完了するまで待機
                waitMediaSetup(player, pos);

                capture(
                    renderTarget,
                    player,
                    (i % maxColumns) * width,
                    (i / maxColumns) * height,
                    width,
                    height,
                    filtering,
                    dpi
                    );
            }

            player.Volume = volume;

            return(Image.ConvertToBitmapImage(renderTarget, Image.ImageType.PNG));
        }