string image 和 byte的互相转换
string str = "测试test"; //convert string to byte byte[] Strbyte =System.Text.Encoding.Default.GetBytes(str); //convert byte to string string tempStr = System.Text.Encoding.Default.GetString(Strbyte); //convert image to byte FileStream fs = new FileStream(@"R:\Engineer Training\Intern Training\Chao\pic\1.png",FileMode.Open); byte[] imageByte = new byte[fs.Length]; fs.Read(imageByte, 0, imageByte.Length); fs.Close(); #region image to byte (2) byte[] photo_byte = null; using (FileStream fs2 = new FileStream(@"R:\Engineer Training\Intern Training\Chao\pic\1.png", FileMode.Open, FileAccess.Read)) { using (BinaryReader br = new BinaryReader(fs2)) { photo_byte = br.ReadBytes((int)fs2.Length); } } #endregion //byte to image MemoryStream ms = new MemoryStream(imageByte); Image photo = Image.FromStream(ms, true); #region byte to image (2) Image photo2 = null; using (MemoryStream ms2 = new MemoryStream(imageByte)) { ms2.Write(imageByte, 0, imageByte.Length); photo2 = Image.FromStream(ms2, true); } #endregion photo.Save(@"R:\Engineer Training\Intern Training\Chao\pic\3.jpg");