在我的代码中,我从字节数组(由Kinect提供)接收WriteableBitmap并希望将其转换为EmguCV可用的位图。目前这是我拥有的代码:
// Copy the pixel data from the image to a temporary array
colorFrame.CopyPixelDataTo(this.colorPixels);
// Write the pixel data into our bitmap
this.colorBitmap.WritePixels(
new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
this.colorPixels,
this.colorBitmap.PixelWidth * colorFrame.BytesPerPixel,
0);
BitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(colorBitmap));
MemoryStream ms = new MemoryStream();
encoder.Save(ms);
Bitmap b=new Bitmap(ms);
Image<Gray, Byte> img = new Image<Gray, Byte>(b);
img = img.ThresholdBinary(new Gray(200), new Gray(255));
我从这里得到了代码的下半部分。代码编译一切正常,但在尝试运行程序时却会停顿(它应该对图像执行一些操作,然后将其转换回可呈现为图像的格式)。我暂停我的代码,然后在VS 2013中使用IntelliTrace,我得到了以下异常:
Image<Gray, Byte> img = new Image<Gray, Byte>(b);
“引发了System.ArgumentException:不支持URI格式。”使用备用代码,直接从字节到位图会给我带来同样的错误。(可以在这里找到代码。)有人有解决此错误或转换为位图的替代方法的提示吗?我是C#和EmguCV的新手,非常感激。