我从 Kinect 传感器获得了一个视频源,它以位图的形式存储。我的问题是如何将一张图片(例如
以下是我试图通过将图像放置在视频源上实现的模拟效果:
绘制方法的更新实现,我认为这不是正确的实现方式,当将图像路径添加到.DrawImage时,我遇到了无效参数错误:
.png
)覆盖到视频源上。
视频源以位图源的方式显示在下面,我知道如何向位图绘制一条线,但如何将资源中的图片绘制到视频源上呢?
KinectVideo.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96,
PixelFormats.Bgr32, null, colorData, colorFrame.Width * colorFrame.BytesPerPixel);
以下是我试图通过将图像放置在视频源上实现的模拟效果:
![我想要叠加到视频源的拳击袋图像。](https://istack.dev59.com/Y4wgJ.webp)
void myKinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (colorFrame == null) return;
byte[] colorData = new byte[colorFrame.PixelDataLength];
colorFrame.CopyPixelDataTo(colorData);
KinectVideo.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96,
PixelFormats.Bgr32, null, colorData, colorFrame.Width * colorFrame.BytesPerPixel);
Rect destRect2;
//drawing image overlay to video feed
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)));
drawingContext.DrawImage("Images/boxbag.jpg", destRect2);
drawingContext.Close();
var mergedImage = new RenderTargetBitmap(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Pbgra32);
mergedImage.Render(drawingVisual);
KinectVideo.Source = mergedImage;
}
}
drawingContext.DrawImage(KinectVideo, destRect1);
和drawingContext.DrawImage(PunchBag, destRect1);
这样就可以将图像绘制到视频中了,或者我理解错了吗? - Brian VardrawingContext.DrawImage(image2, destRect2);
处得到了无效参数的错误提示。 - Brian VarBitmapImage
。 - aybe