我在windows服务中自我托管OWIN/KATANA。现在,我已经实现了一种从相机中获取单个图像的方法。我想从相机抓取多个帧,并将它们流回html页面上的img标记。这有可能是奥林/卡塔那吗?
发布于 2015-10-23 18:38:45
app.Map("/Camera/Video", a =>
{
a.Run(context =>
{
string connectionid = CurrentDevice.Value.ToString();
object ret = DeviceManager.Instance.SendMessageToDevice(connectionid, "startmovie");
context.Response.Headers.Add("Content-Type", new string[] { "multipart/x-mixed-replace; boundary=--jpgboundary" });
bool con = true;
StreamWriter writer = new StreamWriter(context.Response.Body);
while (con)
{
using (MemoryStream ms = new MemoryStream())
{
Image img = (Image)DeviceManager.Instance.SendMessageToDevice(connectionid, "capturestill");
img.Save(ms, ImageFormat.Jpeg);
byte[] buffer = ms.GetBuffer();
writer.WriteLine("--jpgboundary");
writer.WriteLine("Content-Type: image/jpeg");
writer.WriteLine(string.Format("Content-length: {0}", buffer.Length));
writer.WriteLine();
context.Response.Write(buffer);
//writer.WriteLine(Convert.ToBase64String(buffer));
writer.Flush();
}
Thread.Sleep(200);
}
DeviceManager.Instance.SendMessageToDevice(connectionid, "stopmovie");
return context.Response.WriteAsync("");
});
});我弄明白了我的问题是什么。我使用的是WriteAsync,我只需要使用写的。上面的效果很好。我现在就想办法阻止这一切。
https://stackoverflow.com/questions/33287437
复制相似问题