C#中图片已经保存于Bitmap中,如何实现将其传送到指定IP地址的计算机上,并在指定计算机上建立窗口显示出来?
这个程序也只要实现局域网中传送就行了。由三个部分组成:第一是抓取屏幕;第二是建立发送,即服务器;第三是接受,即客户端,并将接受的图片在窗口中显示出来。...
这个程序也只要实现局域网中传送就行了。由三个部分组成:第一是抓取屏幕;第二是建立发送,即服务器;第三是接受,即客户端,并将接受的图片在窗口中显示出来。
展开
若以下回答无法解决问题,邀请你更新回答
2个回答
展开全部
关键性代码给你:
_client = _listener.AcceptTcpClient();
NetworkStream ns = _client.GetStream();
StreamReader sr = new StreamReader(ns);
BinaryWriter br = new BinaryWriter(ns);
Rectangle rect = Screen.PrimaryScreen.Bounds;
//获得桌面Graphics
Graphics g1 = Graphics.FromHwnd(GetDesktopWindow());
//得到桌面dc
IntPtr dc1 = g1.GetHdc();
Image image = new Bitmap(rect.Width, rect.Height);
Graphics g2 = Graphics.FromImage(image);
IntPtr dc2 = g2.GetHdc();
//截屏到image
BitBlt(dc2, 0, 0, rect.Width, rect.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
//image类型转到二进制
byte[] b = ImageToByteArray(image);
//发送
br.Write(b, 0, b.Length);
br.Flush();
image.Dispose();
//ImageToByteArray函数
public byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
发送到客户端后再把二进制转成image类型,显示出来,
public Image ByteArrayToImage(byte[] byteArrayIn, int count)
{
MemoryStream ms = new MemoryStream(byteArrayIn, 0, count);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
不懂发消息给我,
_client = _listener.AcceptTcpClient();
NetworkStream ns = _client.GetStream();
StreamReader sr = new StreamReader(ns);
BinaryWriter br = new BinaryWriter(ns);
Rectangle rect = Screen.PrimaryScreen.Bounds;
//获得桌面Graphics
Graphics g1 = Graphics.FromHwnd(GetDesktopWindow());
//得到桌面dc
IntPtr dc1 = g1.GetHdc();
Image image = new Bitmap(rect.Width, rect.Height);
Graphics g2 = Graphics.FromImage(image);
IntPtr dc2 = g2.GetHdc();
//截屏到image
BitBlt(dc2, 0, 0, rect.Width, rect.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
//image类型转到二进制
byte[] b = ImageToByteArray(image);
//发送
br.Write(b, 0, b.Length);
br.Flush();
image.Dispose();
//ImageToByteArray函数
public byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
发送到客户端后再把二进制转成image类型,显示出来,
public Image ByteArrayToImage(byte[] byteArrayIn, int count)
{
MemoryStream ms = new MemoryStream(byteArrayIn, 0, count);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
不懂发消息给我,
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
socket
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询