public void CompositeFrame(CompositeVideoFrameContext context) { IDirect3DSurface outputSurface = context.OutputFrame.Direct3DSurface; using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(_canvasDevice, outputSurface)) using (CanvasDrawingSession drawSession = renderTarget.CreateDrawingSession()) { foreach (var overlaySurface in context.SurfacesToOverlay) { var overlay = context.GetOverlayForSurface(overlaySurface); var width = (float)overlay.Position.Width; var height = (float)overlay.Position.Height; using (var overlayBitmap = CanvasBitmap.CreateFromDirect3D11Surface(_canvasDevice, overlaySurface)) using (var videoBrush = new CanvasImageBrush(_canvasDevice, overlayBitmap)) { var scale = width / overlay.Clip.GetVideoEncodingProperties().Width; videoBrush.Transform = Matrix3x2.CreateScale(scale) * Matrix3x2.CreateTranslation((float)overlay.Position.X, (float)overlay.Position.Y); drawSession.FillEllipse(new Vector2((float)overlay.Position.X + width / 2, (float)overlay.Position.Y + height / 2), width / 2, height / 2, videoBrush); } } drawSession.DrawText("Party\nTime!", new Vector2(_backgroundProperties.Width / 1.5f, 100), Windows.UI.Colors.CornflowerBlue, new CanvasTextFormat() { FontSize = (float)_backgroundProperties.Width / 13, FontWeight = new FontWeight() { Weight = 999 }, HorizontalAlignment = CanvasHorizontalAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Center }); } }
/// <summary> /// Composite the frame /// </summary> /// <param name="context">the composite frame context</param> public void CompositeFrame(CompositeVideoFrameContext context) { foreach (var surface in context.SurfacesToOverlay) { using (var inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(MediaExtension.Device, surface)) using (var renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(MediaExtension.Device, context.OutputFrame.Direct3DSurface)) using (var ds = renderTarget.CreateDrawingSession()) using (var chromaKeyEffect = MediaExtension.CreateChromaKeyEffect(inputBitmap)) { var overlay = context.GetOverlayForSurface(surface); var destinationRectangle = overlay.Position; var sourceRectangle = inputBitmap.Bounds; var opacity = System.Convert.ToSingle(overlay.Opacity); ds.DrawImage(chromaKeyEffect, destinationRectangle, sourceRectangle, opacity); } } }