C# 图片与Byte相互转换



       备注:原资料地址已经忘记,但代码并非我自己写出的。

    

  

        private byte[] GetIMGbyte(string PicturePath)
        {
            //将需要存储的图片读取为数据流
            FileStream fs = new FileStream(@PicturePath, FileMode.Open, FileAccess.Read);
            Byte[] btye2 = new byte[fs.Length];
            fs.Read(btye2, 0, Convert.ToInt32(fs.Length));
            fs.Close();
            return btye2;
        }


     

        public System.Drawing.Image ReturnPhoto(byte[] streamByte)
        {

            //将数据流读取为图片
            System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte);
            System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
            return img;
        }

你可能感兴趣的:(ASP.NET,C#,C/S,ASP.NET)