2011-09-01 65 views
0

我試圖將PlanarImage位轉換爲WPF應用程序的pRgb32buffer,以便在VcamSDK提供的虛擬網絡攝像頭上顯示它。我不知道pRgb32buffer是什麼,但e2eSoft需要它作爲VcamSDK中的覆蓋參數。有關addOverlay方法的文檔如下所示;如何從BitmapSource或PlanarImage(從Kinect)抓取pRgb32圖像緩衝區?

HRESULT AddOverlay([in] VARIANT pRgb32Buffer, [in] ULONG width, [in] ULONG height 
    , [in] LONG px, [in] LONG py, [in] ULONG whichOne); 
Add an image overlay to current VCam video. 
pRgb32Buffer: overlay image buffer, in RGB32 format (with alpha channel), size is 
    [width x height], if it's NULL, this overlay (whichOne) will be removed; 
px, py: overlay position, [0, 0] is left-top point; 
whichOne: VCam support 5 image overlay (0~4). 

而PlanarImage的代碼如下,PixelFormat是Bgr32,所以也需要一點轉換;

void _nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e) 
    PlanarImage Image = e.ImageFrame.Image; 
    video.Source = BitmapSource.Create(
     Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, 
      Image.Bits, Image.Width * Image.BytesPerPixel); 

我在Google上搜索了pRgb32,但只發現有限的信息,並且沒有關於vCam SDK的示例文檔。

我不是真正的圖像處理專家,所以任何幫助表示讚賞!謝謝!


編輯:

我想我可以使用PlayVideoFile(string fileName);方法也存在於SDK,但它需要圖像的URI來顯示。而且我無法將它保存到硬盤上以對我的應用程序進行一些限制(我可能多次更改圖像並從圖像製作流視頻,如果我嘗試保存它,運行時會給我一個當前存在的錯誤使用),我不配偶有黑客或無論如何發送佈局圖像作爲Uri參數?


UPDATE:

我已經成功使用以下比特轉換,正如我理解超高動力學沒有使用Alpha通道這樣就可發送所有的α-位0。首先我解決了這個問題(圖像由於0 alpha而不可見),那麼我已經完成了以下從BGRA(Kinect)到ABGR(所需像素格式)的轉換。該文件有點妄想,說它是RGB格式的alpha通道,花了一點時間瞭解真正的格式是ABGR。

這裏是轉換:

for (int i = 0; i < myBits.Length; i+=4) 
    { 
     for (int j = 0; j < 4; j++) 
     { 
      tempBit = myBits[i + j]; 
      myBits[i + j] = myBits[i + 3]; 
      myBits[i + 3] = tempBit; 
     } 
     myBits[i] = 255; 
    } 

如果有人能幫助我做到這一點以更有效的方式,我很樂意接受他們的答案。否則我不知道如何解決問題?

回答

0

我想你可以簡單地取下內進行,並做到:


for (int i = 0; i < myBits.Length; i+=4) 
{ 
    myBits[i+3] = myBits[i+2]; 
    myBits[i+2] = myBits[i+1]; 
    myBits[i+1] = myBits[i]; 
    myBits[i] = 255; 
}