110,533
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.IO;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using System.Threading;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
Socket revSocket = null;
static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
public Form1()
{
InitializeComponent();
}
//public delegate void InvokeDelegate();
private void Form1_Load(object sender, EventArgs e)
{
revSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
revSocket.Connect(IPAddress.Parse("192.168.1.104"), 8016);
revSocket.ReceiveBufferSize = 131072;
pictureBox1.Width = Screen.PrimaryScreen.Bounds.Width;
pictureBox1.Height = Screen.PrimaryScreen.Bounds.Height;
print();
}
private void print() {
myTimer.Tick += new EventHandler(out1);
// Sets the timer interval to 5 seconds.
myTimer.Interval = 2000;
myTimer.Start();
}
public void out1(Object myObject,
EventArgs myEventArgs)
{
byte[] file = new byte[65536];
revSocket.Receive(file);
MemoryStream ms = new MemoryStream(file);
Image image = Image.FromStream(ms);//出错行
//image.Save(@"c:\aa\j.gif", ImageFormat.Gif);
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBox1.Image = image;
ms.Close();
}
}
}