C# pictureBox显示图片问题

smile2014_007 2015-03-31 08:11:36
下面是代码,请问为什么pictureBox显示的永远是第一张图片,而连续的显示图片出来
public void thread()
{
byte[] data_len = new byte[10];
byte[] pic_data = new byte[1455 * 8];
data[0] = (byte)0x47;
data[1] = (byte)0x50;
int len = 0;
int size = 0;
int time=0;
bool working = true;
TcpClient client = new TcpClient();
IPEndPoint IE = new IPEndPoint(IPAddress.Parse(addr), port);
client.Connect(IE);
if (client != null)
{
while(true)
{

len = 0;
int times = 0;
networkStream = client.GetStream();
networkStream.Write(data, 0, data.Length);
networkStream.Read(data_len, 0, 10);

while (working)
{
networkStream.Read(pic_data, len, 1455);
times++;
len = len + 1455;
if (times >= 3)
{
for (int k = 1; k < len; k++)
{
if (pic_data[k - 1] == (byte)0xff)
if (pic_data[k] == (byte)0xd9)
{
working = false;
times = 0;
break;
}
}
}
}
string pic_add = fileAddr + time + ".jpg";
DownLoadFile(pic_add,pic_data);
Image img = bytesToImg(pic_data, 0);
// if(pictureBox1.Image.)
// pictureBox1.Image.Dispose();
pictureBox1.Image = img;
time++;

}

}
else
{

}
}
...全文
221 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
smile2014_007 2015-04-04
  • 打赏
  • 举报
回复
引用 1 楼 starfd 的回复:
pic_data = new byte[1455 * 8]; 放到第一个while(true)里面去
引用 2 楼 lovelj2012 的回复:
time++之后重新初始化pic_data

pic_data = new byte[1455 * 8];
引用 3 楼 Mittermeyer 的回复:
bytesToImg怎么写的? pictureBox1.Image = img; 之后调用一下pictureBox1.Refresh(),看看是否可以。
引用 4 楼 wyd1520 的回复:
楼主你这介面被卡死了吧。
好了,谢谢各位,我换其他方法了,用了定时器,解决了
本拉灯 2015-04-01
  • 打赏
  • 举报
回复
楼主你这介面被卡死了吧。
Mittermeyer 2015-04-01
  • 打赏
  • 举报
回复
bytesToImg怎么写的? pictureBox1.Image = img; 之后调用一下pictureBox1.Refresh(),看看是否可以。
江南小鱼 2015-03-31
  • 打赏
  • 举报
回复
time++之后重新初始化pic_data

pic_data = new byte[1455 * 8];
  • 打赏
  • 举报
回复
pic_data = new byte[1455 * 8]; 放到第一个while(true)里面去

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧