Esempio n. 1
0
        public BitmapSource MakeFrame(int width, int height, BitmapSource rawFrame, FrameMetadata metadata, BitmapSource baseFrame)
        {
            DrawingVisual visual = new DrawingVisual();

            using (var context = visual.RenderOpen())
            {
                if (baseFrame != null)
                {
                    var fullRect = new Rect(0, 0, width, height);
                    context.DrawImage(baseFrame, fullRect);
                }

                var rect = new Rect(metadata.Left, metadata.Top, metadata.Width, metadata.Height);
                context.DrawImage(rawFrame, rect);
            }
            var bitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default);

            bitmap.Render(visual);

            var result = new WriteableBitmap(bitmap);

            if (result.CanFreeze && !result.IsFrozen)
            {
                result.Freeze();
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 获得帧的元数据
        /// </summary>
        /// <param name="frame"></param>
        /// <returns></returns>
        public FrameMetadata GetFrameMetadata(BitmapFrame frame)
        {
            var metadata      = (BitmapMetadata)frame.Metadata;
            var delay         = TimeSpan.FromMilliseconds(100);
            var metadataDelay = metadata.GetQueryOrDefault("/grctlext/Delay", 10);

            if (metadataDelay != 0)
            {
                delay = TimeSpan.FromMilliseconds(metadataDelay * 10);
            }
            var frameMetadata = new FrameMetadata
            {
                Left   = metadata.GetQueryOrDefault("/imgdesc/Left", 0),
                Top    = metadata.GetQueryOrDefault("/imgdesc/Top", 0),
                Width  = metadata.GetQueryOrDefault("/imgdesc/Width", frame.PixelWidth),
                Height = metadata.GetQueryOrDefault("/imgdesc/Height", frame.PixelHeight),
                Delay  = delay
            };

            return(frameMetadata);
        }