我想製作一個使用相機的應用程序,從中獲取相框,將其轉換並放到屏幕上。我從微軟發現了一個教程,它將灰度轉換爲灰度,但我並不需要它。相反,我需要那個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。 謝謝。
似乎WP8開發不支持Bitmap.Only BitmapImage,但我不能像你說的那樣使用它。 –
在這種情況下,您可能必須將其轉換爲2維數組,然後像這樣對它進行操作而不是位圖。 – BlargleMonster