C# 如何读取本地MJPEG文件
我正在为XNA中的Windows Phone编写一个应用程序。。。我想阅读应用程序资源中存储的MJPEG流。我发现了许多通过WebHttpRequest从网站获取MJPEG的示例,如下所示:C# 如何读取本地MJPEG文件,c#,.net,xna,jpeg,mjpeg,C#,.net,Xna,Jpeg,Mjpeg,我正在为XNA中的Windows Phone编写一个应用程序。。。我想阅读应用程序资源中存储的MJPEG流。我发现了许多通过WebHttpRequest从网站获取MJPEG的示例,如下所示: // get the response HttpWebRequest request = (HttpWebRequest) asyncResult.AsyncState; HttpWebResponse response = (HttpWebResponse)
// get the response
HttpWebRequest request = (HttpWebRequest) asyncResult.AsyncState;
HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(asyncResult);
try {
// find boundary value
string contentType = response.Headers["Content-Type"];
if (!String.IsNullOrEmpty(contentType) && !contentType.Contains("=")) {
throw new FormatException("Invalid content-type header. The source is likely not returning a proper MJPEG stream.");
}
string boundary = response.Headers["Content-Type"].Split('=')[1].Replace("\"", "");
byte[] boundaryBytes = Encoding.UTF8.GetBytes(boundary.StartsWith("--") ? boundary : "--" + boundary);
using (Stream stream = response.GetResponseStream()) {
using (BinaryReader binaryReader = new BinaryReader(stream)) {
// code to parse the MJPEG stream
}
}
} finally {
response.Close();
}
。。。但这并不是我想要的。下面是我从应用程序资源中将MJPEG作为二进制流读取的代码:
private void ParseMjpeg(object uri)
{
// what the corresponding code for determining the boundary bytes in my local MJPEG?
byte[] boundaryBytes = ???
using (Stream stream = TitleContainer.OpenStream(uri.ToString())) {
using (BinaryReader binaryReader = new BinaryReader(stream)) {
// code to parse the MJPEG stream as before: OK
}
}
}
如何确定上面代码中的边界字节?任何帮助都将不胜感激
谢谢,
j3d这会让你的生活更轻松。据我所知,DLL应该为您提供您所需要的大部分内容
这会让你的生活轻松很多。据我所知,DLL应该为您提供您所需要的大部分内容