我有一個由位圖存儲的圖像託管的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的正確參數? –