C#tcp如何发送图片二进制流,最好有实例,谢谢
展开全部
序列化之后转成二进制流发送, 接收之后再转成图片
图片转成二进制流
MemoryStream ms = null;
try
{
ms = new MemoryStream();
bitmap.Save(ms, Bitmap.RawFormat);
byte[] byteImage = new Byte[ms.Length];
byteImage = ms.ToArray(); //发送byteImage
}
catch (ArgumentNullException ex)
{
throw ex;
}
finally
{
ms.Close();
}
二进制流转成图片
MemoryStream stream = null;
try
{
stream = new MemoryStream(byteImage); // byteImage就是接收到的二进制数组
bitmap = ((Image)new Bitmap(stream));
}
catch (ArgumentNullException ex)
{
throw ex;
}
catch (ArgumentException ex)
{
throw ex;
}
finally
{
stream.Close();
}
图片转成二进制流
MemoryStream ms = null;
try
{
ms = new MemoryStream();
bitmap.Save(ms, Bitmap.RawFormat);
byte[] byteImage = new Byte[ms.Length];
byteImage = ms.ToArray(); //发送byteImage
}
catch (ArgumentNullException ex)
{
throw ex;
}
finally
{
ms.Close();
}
二进制流转成图片
MemoryStream stream = null;
try
{
stream = new MemoryStream(byteImage); // byteImage就是接收到的二进制数组
bitmap = ((Image)new Bitmap(stream));
}
catch (ArgumentNullException ex)
{
throw ex;
}
catch (ArgumentException ex)
{
throw ex;
}
finally
{
stream.Close();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询