图片和string的转换

FileStream photo = new FileStream("test.jpg", FileMode.Open);
            byte[] buffer = new byte[65000];
            photo.Read(buffer, 0, buffer.Length);
            Console.WriteLine("这里将图片转成String:");
            string photoStr = Encoding.ASCII.GetString(buffer);
            Console.Write("转换成功!");
            photo.Close();

            Console.WriteLine("以下是讲String转换成图片:");
            FileStream newPhoto = new FileStream("newPhoto.jpg", FileMode.Create);
            newPhoto.Write(buffer, 0, buffer.Length);
            //Image ima = Image.FromStream(newPhoto);
            newPhoto.Close();
            Console.WriteLine("转换成功!");
            Console.ReadKey();

你可能感兴趣的:(图片和string的转换)