110,536
社区成员
发帖
与我相关
我的任务
分享
int SendedCount = 0;
long totalLength = 0;
List<byte[]> list = new List<byte[]>();
while (true)
{
byte[] data = TransferFiles.ReceiveVarData(client);
totalLength += data.Length;
if (data.Length == 0)
{
break;
}
else
{
SendedCount++;
list.Add(data);
}
}
if (totalLength>0)
{
byte[] imagebytes = new byte[totalLength];
imagebytes=list.ToArry();
}
SqlCommand com = new SqlCommand("select top 1 ImageList from Picture",con);
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
//imagebytes = (byte[])dr.GetValue(1);
if (dr.GetValue(0) != DBNull.Value)
{
imagebytes = (byte[])dr.GetValue(0);
MemoryStream ms = new MemoryStream(imagebytes);
Bitmap bmpt = new Bitmap(ms);
pictureBox1.Image = bmpt;
}
但是我用上面的方法,无法打开图片。
if (totalLength > 0)
{
byte[] imagebytes = new byte[totalLength];
Int32 startIndex = 0;
for (int i = 0; i < list.Count; i++)
{
byte[] temp = list[i];
temp.CopyTo(imagebytes,startIndex);
startIndex += temp.Length;
}
}