我有一個(gè)方法可以更新 WriteableBitmap (FrameDataNew) 的內(nèi)容,它是我的視圖模型 (VM) 中的一個(gè)屬性: public WriteableBitmap FrameDataNew { get { return frameDataNew; } set { frameDataNew = value; OnProptertyChanged("FrameDataNew"); } } private WriteableBitmap frameDataNew = null; 當(dāng)我從我編寫(xiě)的 gstreamer 類(lèi)收到一個(gè)新的位圖時(shí),我更新 FrameDataNew 以便在屏幕上顯示最新的幀。該窗口是一個(gè)簡(jiǎn)單的 Image 控件,其源綁定到 FrameDataNew。以下代碼可以很好地在我的事件處理程序中執(zhí)行此操作: /// <summary> /// BitmapCaptured event handler for when a new video frame is received from the IP source /// </summary> /// <param name="sender">The originating source of the event</param> /// <param name="NewBitmap">The new frame in Bitmap form</param> private void PipeLine_BitmapCaptured(object sender, Bitmap NewBitmap) { // render to the screen Dispatcher.Invoke(() => { // check the existence of the WriteableBitmap and also the dimensions, create a new one if required if ((VM.FrameDataNew == null) || (VM.FrameDataNew.Width != NewBitmap.Width) || (VM.FrameDataNew.Height != NewBitmap.Height)) VM.FrameDataNew = new WriteableBitmap(NewBitmap.Width, NewBitmap.Height, NewBitmap.HorizontalResolution, NewBitmap.VerticalResolution, PixelFormats.Bgr24, null); // lock the bitmap data so we can use it BitmapData data = NewBitmap.LockBits(new Rectangle(0, 0, NewBitmap.Width, NewBitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);現(xiàn)在我想更新我的程序以處理多個(gè)管道和 WriteableBitmaps,以便我可以顯示多個(gè)視頻源。我做的第一件事是創(chuàng)建一個(gè)靜態(tài)實(shí)用程序類(lèi),以便我可以傳入我希望更新的新位圖 (NewBitmap) 和 WriteableBitmap (VM.FrameDataNew)。圖像不再出現(xiàn)在屏幕上。單步執(zhí)行代碼,每次調(diào)用 InjectBitmap() 時(shí),目標(biāo) WriteableBitmap 是否為空?代碼在第一個(gè) if 語(yǔ)句中創(chuàng)建了一個(gè)新的,但 VM.FrameDataNew 保持為空?我絕對(duì)處于我在這方面經(jīng)驗(yàn)的邊緣,因此非常感謝任何幫助。
- 1 回答
- 0 關(guān)注
- 163 瀏覽
添加回答
舉報(bào)
0/150
提交
取消