首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何读取本地MJPEG文件

如何读取本地MJPEG文件
EN

Stack Overflow用户
提问于 2012-06-28 04:25:59
回答 1查看 2K关注 0票数 1

我正在为XNA中的Windows Phone编写一个应用程序...我想读取存储在应用程序资源中的MJPEG流。我找到了很多通过WebHttpRequest从网站获取MJPEG的例子,如下所示:

代码语言:javascript
复制
        // 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作为二进制流从应用程序的资源中读取的代码:

代码语言:javascript
复制
    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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-28 05:54:53

这应该会让你的生活变得更容易。据我所知,DLL应该能为您提供所需的大部分内容。

http://channel9.msdn.com/coding4fun/articles/MJPEG-Decoder

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11234327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档