Image.FromStream报错参数无效

charles27823349 2009-09-29 10:58:05
byte[] inum = new byte[32];
revSocket.Receive(inum);
int aa = BitConverter.ToInt32(inum, 0);
byte[] ib = new byte[aa];
revSocket.Receive(ib);
MemoryStream ms = new MemoryStream(ib);
Image image = Image.FromStream(ms);//出错行
有时候行,有时候就不行
...全文
672 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我也遇到了使用Image.Fromstream()时程序报参数无效。悲催
破碎的脸 2009-09-30
  • 打赏
  • 举报
回复
ms不能释放,不能为null,不能Flash()
CHN_smallfox 2009-09-30
  • 打赏
  • 举报
回复
这个问题我好像已经回答你了,怎么不参考一下呢?
charles27823349 2009-09-30
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wartim 的回复:]

MemoryStream ms = new MemoryStream(...);
byte[] x=ms.ToArray();
Convert.ToBase64String(x); 


Convert.FromBase64CharArray(...)
[/Quote]
可是socket接受发送都用byte啊
wartim 2009-09-30
  • 打赏
  • 举报
回复

MemoryStream ms = new MemoryStream(...);
byte[] x=ms.ToArray();
Convert.ToBase64String(x);


Convert.FromBase64CharArray(...)
it_gz_xi 2009-09-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 a8352081 的回复:]
你可以用序列化来传图片嘛
[/Quote]
同意
charles27823349 2009-09-30
  • 打赏
  • 举报
回复
该怎么传呢
boringame 2009-09-30
  • 打赏
  • 举报
回复
为什么要这样用呢?
a8352081 2009-09-30
  • 打赏
  • 举报
回复
你可以用序列化来传图片嘛
charles27823349 2009-09-30
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.IO;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using System.Threading;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
Socket revSocket = null;

static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
public Form1()
{
InitializeComponent();
}
//public delegate void InvokeDelegate();
private void Form1_Load(object sender, EventArgs e)
{
revSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
revSocket.Connect(IPAddress.Parse("192.168.1.104"), 8016);
revSocket.ReceiveBufferSize = 131072;
pictureBox1.Width = Screen.PrimaryScreen.Bounds.Width;
pictureBox1.Height = Screen.PrimaryScreen.Bounds.Height;
print();
}
private void print() {
myTimer.Tick += new EventHandler(out1);

// Sets the timer interval to 5 seconds.
myTimer.Interval = 2000;
myTimer.Start();
}
public void out1(Object myObject,
EventArgs myEventArgs)
{
byte[] file = new byte[65536];
revSocket.Receive(file);


MemoryStream ms = new MemoryStream(file);

Image image = Image.FromStream(ms);//出错行
//image.Save(@"c:\aa\j.gif", ImageFormat.Gif);
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBox1.Image = image;
ms.Close();
}
}
}
charles27823349 2009-09-30
  • 打赏
  • 举报
回复
大小是一样的啊,判断了还是不行
l171147904 2009-09-29
  • 打赏
  • 举报
回复
为接受完全! 你就转化 ,当然错!
看看 发送时候大小,和 你转化时候的大小》?

需要判断是否接受完!Socket 是 分包发送的!

110,533

社区成员

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

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

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