How to draw/overlay an image file to a bitmap image?

前端 未结 2 1234
一整个雨季
一整个雨季 2021-01-06 13:20

I have a video feed from a Kinect sensor hosted by an image stored as a bitmap. My question is how do I overlay an image, for example a .png on to the video fee

2条回答
  •  甜味超标
    2021-01-06 13:56

    To create merged image you can use DrawingContext that gives you methods like DrawText or DrawImage and then render it using RenderTargetBitmap.Render:

    var drawingVisual = new DrawingVisual();
    var drawingContext = drawingVisual.RenderOpen();
    drawingContext.DrawImage(BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, colorData, colorFrame.Width * colorFrame.BytesPerPixel), 
                              new Rect(new Size(colorFrame.Width, colorFrame.Height)));
    var overlayImage = new BitmapImage(new Uri("Images/boxbag.jpg"));
    drawingContext.DrawImage(overlayImage, 
                              new Rect(x, y, overlayImage.Width, overlayImage.Height));
    drawingContext.Close();
    var mergedImage = new RenderTargetBitmap(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Pbgra32);
    mergedImage.Render(drawingVisual);
    
    KinectVideo.Source = mergedImage;
    

提交回复
热议问题