rt。void Fun(Image image)
{
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
bytes = StreamToBytes(ms);
Stream ms2 = BytesToStream(bytes);
if (Form == null)
{
Form = new Form2();
Form.pictureBox1.Image = Image.FromStream(ms2);//参数无效
Form.ShowDialog();
}
}
private byte[] StreamToBytes(Stream stream)
{
byte[] bytes=new byte[stream.Length];
stream.Read(bytes, 0,bytes.Length);
stream.Seek(0, SeekOrigin.Begin);
return bytes;
}
private Stream BytesToStream(byte[] bytes)
{
Stream stream = new MemoryStream(bytes);
return stream;
}
{
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
bytes = StreamToBytes(ms);
Stream ms2 = BytesToStream(bytes);
if (Form == null)
{
Form = new Form2();
Form.pictureBox1.Image = Image.FromStream(ms2);//参数无效
Form.ShowDialog();
}
}
private byte[] StreamToBytes(Stream stream)
{
byte[] bytes=new byte[stream.Length];
stream.Read(bytes, 0,bytes.Length);
stream.Seek(0, SeekOrigin.Begin);
return bytes;
}
private Stream BytesToStream(byte[] bytes)
{
Stream stream = new MemoryStream(bytes);
return stream;
}
stream.Seek(0, SeekOrigin.Begin);
stream.Read(bytes, 0,bytes.Length);
这两句代码的位置颠倒一下位置。
image.Save()后,Stream流中的位置在末尾,先把位置移到开始在读取,否则你读取到一个空。
用LS说的这个方法也可以:
byte[] byTest = ms.ToArray()