我有一个由位图存储的图像托管的Kinect传感器的视频源。我的问题是,如何将图像叠加到视频供稿上,例如.png
。如何绘制/覆盖图像文件到位图图像?
视频输入如下图所示显示为位图源,我知道如何绘制一条线到位图,但是如何从资源中绘制图像到它?
KinectVideo.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96,
PixelFormats.Bgr32, null, colorData, colorFrame.Width * colorFrame.BytesPerPixel);
下面是达到我想要通过将图像通过视频饲料,实现了模拟:
更新执行绘制方法的,我不认为这
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);',这会将图像绘制到Feed上或忘了这个错误? –
请检查我的更新 – dkozl
好吧,我试过更新后的代码,但是这一行令我困惑,'drawingContext.DrawImage(“Images/bbag.jpg”,destRect2);'什么是destRect2,我必须声明它是图像路径图像2的正确参数? –