问题描述
黑客,
所以我一直在尝试使用System.Windows.Media.Imaging命名空间,并且我正在尝试通过Silverlight Web应用程序访问Web cam.我可以获取网络摄像头的实时供稿,甚至可以将帧捕获到Rectangle中,但是我发现自己陷入了死胡同,无法将该帧保存到图像文件(.png或.jpg)中.
捕获的帧基本上是一个WriteableBitmap,下面显示的代码将WriteableBitmap的像素数组转换为字节,然后将其泵出到文件中.
Hi Hackers,
SO i have been dabbling a little bit with System.Windows.Media.Imaging namespace and I am experimenting with accessing web cam through a silverlight web app. I can get the webcam''s live feed and even capture a frame to a Rectangle, but I am finding myself at a dead end not being able to save that frame to an image file (.png or .jpg).
The frame captured is basically a WriteableBitmap and the below shown code converts the pixel array of the WriteableBitmap to bytes and pumps them out to a file.
BinaryWriter bw = new BinaryWriter(new FileStream(path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite));
for (int i = 0; i < a_pixels.Length; i++)
{
bw.Write((byte)a_pixels[i]);
}
bw.Flush();
bw.Close();
事实证明,它确实创建了一个文件,但显然格式不正确,这意味着还需要做更多的工作才能将其呈现为图像格式.我的问题是您认为我可能会想念什么?".请不要将我转发给开源库或类似的文件,因为我希望自己能够做到这一点,这就是为什么我尚未选择第三方库的原因.
帮助非常感谢.谢谢.如果您需要更多信息,请告诉我.
干杯.
Turns out it does create a file but obviously not in the correct format which means something more has to be done to render it into an image format. Which is what my question is "what do you think I may be missing?". Please don''t forward me to open source libraries or anything like that coz I want to be able to do this myself which is why I haven''t already opted for third party libs.
Help much appreciated. Thanks. Please let me know if you need more info.
Cheers.
推荐答案
这篇关于将WriteableBitmap转换为位图以保存到图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!