在 C# 中保存来自 Web 请求的图像

发布于 2024-12-08 14:12:12 字数 129 浏览 2 评论 0原文

我正在使用 jQuery 网络摄像头插件与页面中的网络摄像头进行通信并拍摄快照。它的工作方式是通过与 Flash 助手进行通信。为了保存图片,它会获取另一个页面的名称并向该页面发送 Web 请求。我已成功收到对方的请求。我想保存该请求中的图像。

I'm using a jQuery webcam plugin to communicate with a webcam in my page and take a snapshot. The way it works is by communicating with a Flash helper. To save the picture it takes the name of another page and sends a web request to that page. And I'm successfully receiving that request on the other. I want to save the image from that request.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝礼 2024-12-15 14:12:12

您声称拥有获取请求的代码,您只需加载图像并将其保存到磁盘即可。这需要清理,但类似以下的内容应该可以工作:

System.IO.Stream respStream = resp.GetResponseStream();
System.Drawing.Image img = System.Drawing.Image.FromStream(respStream );
img.Save(PathToSaveTo):

You claim to have the code for getting the request, you just need to load the image and save it to disk. This needs cleaned up, but something like the following should work:

System.IO.Stream respStream = resp.GetResponseStream();
System.Drawing.Image img = System.Drawing.Image.FromStream(respStream );
img.Save(PathToSaveTo):
宫墨修音 2024-12-15 14:12:12

我已经这样做了,它对我有用。

protected void Page_Load(object sender, EventArgs e)
    {
        string strFile = DateTime.Now.ToString("dd_MMM_yymmss") + ".jpg";
      FileStream log = new FileStream(Server.MapPath(strFile),
       FileMode.OpenOrCreate);
        byte[] buffer = new byte[1024];
        int c;
        while ((c = Request.InputStream.Read(buffer, 0, buffer.Length)) > 0)
        {
            log.Write(buffer, 0, c);
        }
       //Write jpg filename to be picked up by regex and displayed on flash html page.
        Response.Write(strFile);
        log.Close();

    }

I Have Done That In This And It Works For Me.

protected void Page_Load(object sender, EventArgs e)
    {
        string strFile = DateTime.Now.ToString("dd_MMM_yymmss") + ".jpg";
      FileStream log = new FileStream(Server.MapPath(strFile),
       FileMode.OpenOrCreate);
        byte[] buffer = new byte[1024];
        int c;
        while ((c = Request.InputStream.Read(buffer, 0, buffer.Length)) > 0)
        {
            log.Write(buffer, 0, c);
        }
       //Write jpg filename to be picked up by regex and displayed on flash html page.
        Response.Write(strFile);
        log.Close();

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文