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个回答
亚远景信息科技
2024-12-11 广告
2024-12-11 广告
上海亚远景信息科技有限公司是国内汽车行业咨询及评估领军机构之一,深耕于ASPICE、敏捷SPICE、ISO26262功能安全、ISO21434车辆网络安全领域,拥有20年以上的行业经验,专精于培训、咨询及评估服务,广受全球车厂及供应商赞誉,...
点击进入详情页
本回答由亚远景信息科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询