GDI+ 中发生一般性错误
voidbgWorker_DoWork(objectsender,DoWorkEventArgse){//打开监听IPAddressipAddress=IPAddress...
void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
//打开监听
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
Socket receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endpoint = new IPEndPoint(ipAddress, 139);
receiveSocket.Bind(endpoint);
receiveSocket.Listen(10);
try
{
while (true)
{
Socket tmpSocket = receiveSocket.Accept();
//当接收到数据时,进行转化成 图像
byte[] buffer = new byte[tmpSocket.ReceiveBufferSize];
if (tmpSocket.Receive(buffer) > 0)
{
using (MemoryStream ms = new MemoryStream(buffer)) // buffer 已经收到数据!
{
Bitmap Origninal = new Bitmap(ms);// 这里报错。。。求救
Bitmap returnBmp = new Bitmap(Origninal.Width, Origninal.Height);
Graphics g = Graphics.FromImage(returnBmp);
g.DrawImage(Origninal, 0, 0);
ms.Close();
Image_ = (Image)returnBmp;
}
} 展开
{
//打开监听
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
Socket receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endpoint = new IPEndPoint(ipAddress, 139);
receiveSocket.Bind(endpoint);
receiveSocket.Listen(10);
try
{
while (true)
{
Socket tmpSocket = receiveSocket.Accept();
//当接收到数据时,进行转化成 图像
byte[] buffer = new byte[tmpSocket.ReceiveBufferSize];
if (tmpSocket.Receive(buffer) > 0)
{
using (MemoryStream ms = new MemoryStream(buffer)) // buffer 已经收到数据!
{
Bitmap Origninal = new Bitmap(ms);// 这里报错。。。求救
Bitmap returnBmp = new Bitmap(Origninal.Width, Origninal.Height);
Graphics g = Graphics.FromImage(returnBmp);
g.DrawImage(Origninal, 0, 0);
ms.Close();
Image_ = (Image)returnBmp;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询