c#.net中,如何将img控件的图片转化为2进制数组?请各位大虾贴出详细代码。。在此谢过。

解决方案 »

  1.   

    public byte[] SetImageToByteArray(string fileName)
        {
            FileStream fs = new FileStream(fileName, FileMode.Open);
            int streamLength = (int)fs.Length;
            byte[] image = new byte[streamLength];
            fs.Read(image, 0, streamLength);
            fs.Close();
            return image;
        }
      

  2.   

    if (Image == null) { return null; }
                byte[] data = null;
                using (MemoryStream ms= new MemoryStream())
                {
                     using (Bitmap Bitmap = new Bitmap(Image))
                    {
                        Bitmap.Save(ms, imageFormat);
                        ms.Position = 0;
                        data = new byte[ms.Length];
                        ms.Read(data, 0, Convert.ToInt32(ms.Length));
                        ms.Flush();
                    }
                }
                return data;
      

  3.   

    去MSDN看下BinaryFomatter类的用法吧