二进制数组和图像相互转换的函数:       //图像转换成二进制       private byte[] ImageToByte(Image Picture)
        {
            MemoryStream ms = new MemoryStream();
            if (Picture == null)
                return new byte[ms.Length];
            Picture.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] BPicture = new byte[ms.Length];
            BPicture = ms.GetBuffer();
            return BPicture;
        }
        //二进制转换为图像
        private Image ByteToImage(byte[] btImage)
        {
            if (btImage.Length == 0)
                return null;
            System.IO.MemoryStream ms = new System.IO.MemoryStream(btImage);
            System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
            return image;
        }1、定义对象public class PicClass
{
        public List<byte[]> img { get; set; }    //图片
} //生成图片的方法
PicClass pc = new PicClass();List<byte[]> imgs = new List<byte[]>();
byte[] img = new byte[0];
img = (byte[])pic.image;       //pic.image是返回的图片的二进制数组
imgs.Add(img);
pc.img = imgs;                    Image image = ByteToImage(btimage);  //将二进制数组转换成image图片
pictureBox1.Image = image;                   //图片显示在picturebox框里 //生成视频的方法List<byte[]> imgs = new List<byte[]>();
myPic pic = new myPic();                             //服务定义的对象
pic=client.queryVioVideo("", "", "", "");       //调用服务获取视频流
byte[] img = new byte[0];
img = (byte[])pic.video;       //pic.video是接收的视频的二进制数组
PicClass pc = new PicClass();
imgs.Add(img);
pc.img=imgs;
File.WriteAllBytes("D://1.avi", pc.img.First()); //将视频流写入到文件里

解决方案 »

  1.   


            private byte[] SetImageToByteArray(string fileName)
            {
                FileStream fs = null;
                try
                {
                    fs = new FileStream(fileName, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite);
                    Bitmap bt = new Bitmap(fs);
                    int streamLength = (int)fs.Length;
                    byte[] image = new byte[streamLength];
                    fs.Read(image, 0, streamLength);
                    return image;
                }
                catch (Exception)
                {
                    throw;            }
                finally
                {
                    fs.Close();
                }
            }
      

  2.   

    什么什么啊?  确定是winform  windows 窗体用的 
      

  3.   

    picturebox 去哪里了? images 是怎么出来的?
      

  4.   

    FileStream fs = new FileStream(@"C:/e06d3510ebfde555cb80c4de.jpg", FileMode.Open);后面要不是固定的图片 要怎么改呢?"C:/e06d3510ebfde555cb80c4de.jpg",   改成 picbox1.ImageLocation ?