2013-04-02 39 views
2

我想製作一個使用相機的應用程序,從中獲取相框,將其轉換並放到屏幕上。我從微軟發現了一個教程,它將灰度轉換爲灰度,但我並不需要它。相反,我需要那個int數組,我必須像8位圖,所以我的轉換函數可以正常工作。所以主要的問題是如何將該像素數據數組轉換爲位圖數組,然後將其返回,以便我可以顯示它屏幕?另一種解決方案是直接從相機獲取位圖int數組,但我該怎麼做?將像素數據轉換爲位圖int數組WP8-C#

我需要在下面的代碼工作:

void PumpARGBFrames() 
    { 
     // Create capture buffer. 
     Width = (int)cam.PreviewResolution.Width; 
     Height = (int)cam.PreviewResolution.Height; 
     int[] ARGBPx = new int[Width * Height]; 

     try 
     { 
      PhotoCamera phCam = (PhotoCamera)cam; 

      while (pumpARGBFrames) 
      { 
       pauseFramesEvent.WaitOne(); 

       phCam.GetPreviewBufferArgb32(ARGBPx); 

       //here i need to do the conversion back and forward 

       pauseFramesEvent.Reset(); 
       Deployment.Current.Dispatcher.BeginInvoke(delegate() 
       { 
        ARGBPx.CopyTo(wb.Pixels, 0); 
        wb.Invalidate(); 

        pauseFramesEvent.Set(); 
       }); 
      } 

     } 
     catch (Exception e) 
     { 
      this.Dispatcher.BeginInvoke(delegate() 
      { 
       // Display error message. 
       txtDebug.Text = e.Message; 
      }); 
     } 
    } 

所以,事實上我並不需要一個位圖,但一個int數組作爲8B位圖的來源。 我從微軟獲得的教程是here。 謝謝。

回答

0

好吧,我認識到,像素數據陣列,其實是一個顏色數組,這是在32b.so我不得不僅32B顏色變換爲8B一個,沒有我想象的那麼難。

謝謝。

0

試着這麼做:

Bitmap bmp = new Bitmap(Width, Height); 

for (int i = 0; i < ARGBPx.Length; ++i) 
{ 
    bmp.SetPixel(
     i % Width, 
     i/Width, 
     /* something to create a Color object from the pixel int value */ 
} 
+0

似乎WP8開發不支持Bitmap.Only BitmapImage,但我不能像你說的那樣使用它。 –

+0

在這種情況下,您可能必須將其轉換爲2維數組,然後像這樣對它進行操作而不是位圖。 – BlargleMonster