using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Drawing;using System.Drawing.Imaging;namespace 图片转化为字符串{ class Program { static void Main(string[] args) { Img2Str(); } public static void Img2Str() { string[] Imge_File = { "E:/01.jpg", "E:/02.jpg", "E:/03.jpg", "E:/04.jpg", "E:/05.jpg", "E:/06.jpg", "E:/07.jpg", "E:/08.jpg", "E:/09.jpg", "E:/10.jpg"}; FileStream Img0 = new FileStream(Imge_File[0], FileMode.Open); FileStream Img1 = new FileStream(Imge_File[1], FileMode.Open); FileStream Img2 = new FileStream(Imge_File[2], FileMode.Open); FileStream Img3 = new FileStream(Imge_File[3], FileMode.Open); FileStream Img4 = new FileStream(Imge_File[4], FileMode.Open); FileStream Img5 = new FileStream(Imge_File[5], FileMode.Open); FileStream Img6 = new FileStream(Imge_File[6], FileMode.Open); FileStream Img7 = new FileStream(Imge_File[7], FileMode.Open); FileStream Img8 = new FileStream(Imge_File[8], FileMode.Open); FileStream Img9 = new FileStream(Imge_File[9], FileMode.Open); int length0 = (int)Img0.Length; byte[] buffer0 = new byte[length0]; Img0.Read(buffer0, 0, length0); string Img_Str0 = Convert.ToBase64String(buffer0); //图片写入字符串中,下同 int length1 = (int)Img1.Length; byte[] buffer1 = new byte[length1]; Img1.Read(buffer1, 0, length1); string Img_Str1 = Convert.ToBase64String(buffer1); int length2 = (int)Img2.Length; byte[] buffer2 = new byte[length2]; Img2.Read(buffer2, 0, length2); string Img_Str2 = Convert.ToBase64String(buffer2); int length3 = (int)Img3.Length; byte[] buffer3 = new byte[length3]; Img3.Read(buffer3, 0, length3); string Img_Str3 = Convert.ToBase64String(buffer3); int length4 = (int)Img4.Length; byte[] buffer4 = new byte[length4]; Img4.Read(buffer4, 0, length4); string Img_Str4 = Convert.ToBase64String(buffer4); int length5 = (int)Img5.Length; byte[] buffer5 = new byte[length5]; Img5.Read(buffer5, 0, length5); string Img_Str5 = Convert.ToBase64String(buffer5); int length6 = (int)Img6.Length; byte[] buffer6 = new byte[length6]; Img6.Read(buffer6, 0, length6); string Img_Str6 = Convert.ToBase64String(buffer6); int length7 = (int)Img7.Length; byte[] buffer7 = new byte[length7]; Img7.Read(buffer7, 0, length7); string Img_Str7 = Convert.ToBase64String(buffer7); int length8 = (int)Img8.Length; byte[] buffer8 = new byte[length8]; Img8.Read(buffer8, 0, length8); string Img_Str8 = Convert.ToBase64String(buffer8); int length9 = (int)Img9.Length; byte[] buffer9 = new byte[length9]; Img9.Read(buffer9, 0, length9); string Img_Str9 = Convert.ToBase64String(buffer9); string Img_Total; Img_Total = Img_Str0; Console.WriteLine(Img_Total.Length); Img_Total += "。"; Console.WriteLine(Img_Total.Length); Img_Total += Img_Str1; Console.WriteLine(Img_Total.Length); Img_Total += "。" + Img_Str2 + "。" + Img_Str3 + "。" + Img_Str4 + "。" + Img_Str5+ "。" + Img_Str6 + "。" + Img_Str7 + "。" + Img_Str8 + "。" + Img_Str9; Console.WriteLine(Img_Total.Length); //分割字符串流为10张图片,分隔符为‘。’ string[] imgs = Img_Total.Split('。'); int Length_New0 = imgs[5].Length; byte[] New0 = new byte[Length_New0]; New0 = Convert.FromBase64String(imgs[5]); //测试代码 int Length_Test = Img_Str9.Length; byte[] Test = new byte[Length_Test]; Test = Convert.FromBase64String(Img_Str9); FileStream NewImg = new FileStream("E:/newimage.jpg",FileMode.Create); FileStream NewImg_buf = new FileStream("E:/newimage_buf.jpg", FileMode.Create); NewImg.Write(Test, 0, Test.Length); NewImg_buf.Write(New0, 0, New0.Length); NewImg.Close(); NewImg_buf.Close(); //Img0.Close(); Console.ReadKey(); } }}
===========================================================================================================================
待处理图片:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
实验截图:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
结果图片路径: