我正在使用Microsoft Surface 2.0 SDK與SUR40 PixelSense兼容計算機。我需要從它的觸摸中捕捉圖像並將其保存爲.bmp
。由於Surface SDK附帶RawImageVisualizer示例,它顯示屏幕上的觸摸圖片,我試圖修改用於將圖片寫入HDD的程序。問題是,在從觸摸捕獲的字節數組構建Image
期間,我得到ArgumentException: Parameter is invalid
。從PixelSense兼容PC中捕獲圖像並將其保存爲.bmp
這是我如何檢索與圖像數據的字節數組從FrameReceivedEventArgs
上FrameReceived
事件:
event.UpdateRawImage(
ImageType.Normalized,
normalizedImage,
0, 0,
InteractiveSurface.PrimarySurfaceDevice.WorkingAreaWidth,
InteractiveSurface.PrimarySurfaceDevice.WorkingAreaHeight);
這就是我嘗試寫字節.bmp
磁盤:
System.Drawing.Image img;
using (System.Drawing.Image raw = System.Drawing.Image.FromStream(new MemoryStream(normalizedImage)))
{
img = raw.Clone() as System.Drawing.Bitmap;
}
img.Save("C:/img.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
所以我得到試圖從流中創建Image
的例外情況。儘管如此,這個字節數組與Texture2D
和SpriteBatch
完全正常工作,它會顯示它。我該如何修復ArgumentException
?