我制作了这段代码来截取屏幕截图-将其转换为字节-将其发送给我的客户,但是当客户收到它时,它变成了一半。
这是代码,它将屏幕截图转换为字节,然后将其发送到我的客户端代码:
public void SendImage()
{
int ScreenWidth = Screen.GetBounds(new Point(0, 0)).Width;
int ScreenHeight = Screen.GetBounds(new Point(0, 0)).Height;
Bitmap bmpScreenShot = new Bitmap(ScreenWidth, ScreenHeight);
Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
gfx.CopyFromScreen(0, 0, 0, 0, new Size(ScreenWidth, ScreenHeight));
bmpScreenShot.Save(Application.StartupPath + "/ScreenShot.jpg", ImageFormat.Jpeg);
byte[] image = new byte[10000*10000*10];
bmpScreenShot = ResizeBitmap(bmpScreenShot, 300, 300);
image = ImageToByte(bmpScreenShot);
sck.Send(image, 0, image.Length, 0);
}
这是接收代码
public void ReceiveImage()
{
if (sck.Connected)
{
{
NetworkStream stream = new NetworkStream(sck);
byte[] data = new byte[10000 * 10000 * 3];
string receive = string.Empty;
Int32 bytes = stream.Read(data, 0, data.Length);
pictureBox1.Image = byteArrayToImage(data);
}
}
}