我用下面的函数转换,提示parameter is not valid,就在fromstream那里    
public Image ByteArrayToImage(byte[] byteArrayIn, int count)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn, 0, count);
            Image returnImage = Image.FromStream(ms);
                        return returnImage;
        } 谢谢各位的帮助!!!

解决方案 »

  1.   

    相片转数据:
                    MemoryStream MS = new MemoryStream();
                    Bitmap bmp = new Bitmap(this.picIndiPhoto.Image);      //picIndiPhoto为Picture控件
                    bmp.Save(MS, ImageFormat.Bmp);
                    Byte[] ImageData = new Byte[MS.Length];                //将相片转为 Byte 类型数据                MS.Position = 0;
                    MS.Read(ImageData, 0, Convert.ToInt32(MS.Length));数据转相片:                        if (!byteArrayIn.Length.Equals(0))
                            {
                                MemoryStream MS = new MemoryStream(byteArrayIn);
                                Bitmap image = new System.Drawing.Bitmap(MS);
                                this.picIndiPhoto.Image = image;   
      }
      

  2.   

    你能保证这个byte[]来自于图像?byte[]起始部分数据是关于图像格式描述的一些信息,如格式,分辨率,颜色信息等,其后才是每个点的RGBA信息,如果你知道特定格式(如BMP)的定义,可以用byte[]描述出一个图像,或者直接从磁盘上读取一个图像文件为字节流,只有这样,才能用Image.FromStream方法获得图像
      

  3.   

    string sql = string.Format("select image from pictures where imageID={0}", imageIndex);
                        DBHelper.conn.Open();
                        cmd = new SqlCommand(sql, DBHelper.conn);
                        byte[] imgs = (byte[])cmd.ExecuteScalar();
                        MemoryStream ms = new MemoryStream(imgs);
                        picMyPic.Image = Image.FromStream(ms);
      

  4.   

    MemoryStream ms = new MemoryStream(byteArrayIn, 0, count); 
    肯定是后面参数有问题。
      

  5.   


    我的byte[]是从一个string转换过来的,这个string是通过特定的获取icon图像命令的来的,有前辈说是PPM格式,我刚才试过从图片直接转byte然后显示没有问题,应该是返回的string转换成byte[]问题。郁闷中。
      

  6.   

    1、
            System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();
            byte[] inputBytes =converter.GetBytes(inputString);
            string  inputString = converter.GetString(inputBytes);
    2、
            string inputString = System.Convert.ToBase64String(inputBytes);
            byte[] inputBytes = System.Convert.FromBase64String(inputString);1、
            System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();
            byte[] inputBytes =converter.GetBytes(inputString);
            string  inputString = converter.GetString(inputBytes);
    2、
            string inputString = System.Convert.ToBase64String(inputBytes);
            byte[] inputBytes = System.Convert.FromBase64String(inputString);
      

  7.   

    MemoryStream ms = new MemoryStream(inputBytes)
    Image  img =Image.FromStream(ms)
      

  8.   

    bitmap bmp=new bitmap(byte[]arrya)
    好象有这个构造函数地
      

  9.   

    用base64编码
    回复内容太短了!
      

  10.   

    string sql = string.Format("select image from pictures where imageID={0}", imageIndex); 
                        DBHelper.conn.Open(); 
                        cmd = new SqlCommand(sql, DBHelper.conn); 
                        byte[] imgs = (byte[])cmd.ExecuteScalar(); 
                        MemoryStream ms = new MemoryStream(imgs); 
                        picMyPic.Image = Image.FromStream(ms);
      

  11.   


        /// <summary>
            /// Image 转换为 byte[]数组
            /// </summary>
            /// <param name="imageIn"></param>
            /// <returns></returns>
            public static byte[] imageToByteArray(System.Drawing.Image imageIn)
            {
                if (imageIn == null)
                    return null;            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                {
                    imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    return ms.ToArray();
                }
            }        /// <summary>
            /// byte[]数组转换为 Image
            /// </summary>
            /// <param name="byteArrayIn"></param>
            /// <returns></returns>
            public static System.Drawing.Image byteArrayToImage(byte[] byteArrayIn)
            {
                if (byteArrayIn == null)
                    return null;            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArrayIn))
                {
                    System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
                    return returnImage;
                }
            }
      

  12.   

    正在研究发回来的string到底是什么格式努力中