首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

string image 跟 byte的互相转换

2013-03-21 
string image 和 byte的互相转换string str 测试test//convert string to bytebyte[] Strbyte Syste

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");

热点排行