我想从服务器向客户端发送图像,我在服务器端编写了这段代码 [英] I want to send an image from the server to client, I wrote this code in server side

查看:111
本文介绍了我想从服务器向客户端发送图像,我在服务器端编写了这段代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图片保存在哪里?我不明白frame.Bitmap.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);意思?保存图像与否它只是一个缓冲区?



我尝试过:



where does the image save? I don't understand what "frame.Bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);" means ? save image or not it is just something like a buffer?

What I have tried:

pictureBox1.Image = frame.ToBitmap();
     MemoryStream ms = new MemoryStream();
     frame.Bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
     bytes = ms.ToArray();
     acc.Send(bytes, 0, bytes.Length, 0);

推荐答案

保存(流,格式)方法保存将图像传递给以指定格式传递给它的流。

Image.Save Method(System.Drawing)| Microsoft Docs [ ^ ]
The Save(stream, format) method saves the image to the stream that is passed into it in the format that is specified.
Image.Save Method (System.Drawing) | Microsoft Docs[^]


它保存到MemoryStream。您可以使用 File.WriteAllBytes(String,Byte [])保存结果(ms.ToArray())。但是,这与将图像发送到客户端无关。您需要在服务器上保存图像,路径可从网站访问,并提供(到客户端)图像的相对路径。
It saves to MemoryStream. You can save the result (ms.ToArray()) using File.WriteAllBytes(String, Byte[]). However, this has nothing to do with sending the image to the client. You need to save image on the server, with the path accessible from the website and provide (to client) relative path to the image.


这篇关于我想从服务器向客户端发送图像,我在服务器端编写了这段代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆